I was trying to do this [question][1] on geeks for geeks. Can someone please tell me what is wrong with my code:
void pairWiseSwap(struct node *head)
{
if(head==NULL||head->next==NULL)
return;
node *i,*j,*tf,*prev;
i=head;
j=i->next;
head=j;
prev=NULL;
while(j!=NULL)
{
if(prev==NULL)
{
tf=j->next;
j->next=i;
i->next=tf;
}
else
{
tf=j->next;
j->next=i;
i->next=tf;
prev->next=j;
}
prev=i;
i=tf;
if(i==NULL)
break;
j=i->next;
}
}
I am trying to swap nodes instead of their data.
Any suggestion ![]()
[1]: https://www.geeksforgeeks.org/pairwise-swap-elements-of-a-given-linked-list/
