I am trying to swap two adjacent nodes in a linked list, and I think I understand the idea of how to do it using a temporary node.
Here is my struct swap function
Simple way to swap to node... I am not writing actual code. I am just giving you a hint to swap nodes.
[1]->[2]->[3]->[4]
Suppose this is your linked list and you want to swap [2]
and [3]
.
[2]
. so your temp
is at [2]
.temp1 = temp->next;
Hence temp1
is at [3]
.temp->next = temp1->next;
temp1->next = temp;
so now temp->next = [4]
and temp1->next = [2]