I was trying to do this [question] on geeks for geeks. Can someone please tell me what is wrong with my code:
void pairWiseSwap(struct node *head)
I am trying to swap nodes instead of their data.
Your code is working fine but your head is not update in main function but your head is not update in main so your 2nd element is missing. To check correctness of your code try
printList(head); from pairWiseSwap function and then from main you will get to know the problem.
Add these lines in your code
struct Node *tmp=start->next;
start = tmp;
and then try printing it will work fine.
Also be careful about corner case when no of elements is list is only 1 or 2. Because above (my steps) code assumes more than 2 elements. So, I keep corner case for you.
Edit more easy was No problem of corner case use this template.
struct Node * pairWiseSwap(struct Node *head)
add returh head; //at each return in function
//in main call by
The problem is I don’t have any information about the main function. This is just a function problem as given in the link above. Also I am handling the corner cases but I can’t find a way to update head.
Thanks for your help:)
Then for first two values you have to go by changing data. And rest can be updated using your code.
OK.THANKS FOR YOUR TIME SIR:)
Welcome @pavitra_ag sir. Happy Coding