top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration Why to Join

Facebook Login
Site Registration

How to swap adjacent element of a single linked list?

0 votes
46 views
How to swap adjacent element of a single linked list?
posted Jul 7, 2017 by Ajay Kumar

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote

You can use any standard swap function and pass the *(node->data) and *(node->next->data) something like -

void SwapDataWithNext(struct Node *node)
{
       /* Swap data of node with its next node's data */
        swap(&node->data, &node->next->data);
}

void swap(int *a, int *b)
{
    int temp;
    temp = *a;
    *a = *b;
    *b = temp;
}
answer Jul 8, 2017 by Salil Agrawal
Similar Questions
+3 votes

How to delete the node that given as argument in single linked list?
Is there any system call to get prev pointer ?

Note: Here the goal is to delete the address not the node's value

Contact Us
+91 9880187415
sales@queryhome.net
support@queryhome.net
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Bangalore-560102
Karnataka INDIA.
QUERY HOME
...