Can You Please give me the hint, how I can solve this?

Can You Please give me the hint, how I can solve this?

Hey @cbcao263 ,
Whenever you come across questions where you have to do the same thing over and over we always think of loops and Recursion !! . So let me give you a hint as to how can you solve the problem using recursion .

Base Case :
If we have only 0 or 1 nodes in the LL we cannot do anything we have to return the LL as it is
Recursion :
We can now visualize the LL as first 2 nodes and then rest of the LL .
So we take out first 2 nodes from the LL and rest of the LL can be swapped in pair by recursion .
We will swap the first 2 nodes yourself.
Then link it to remaining LL which we got from recursive approach .

Hope it helps :blush: .
If your doubt is now resolved please mark it as resolved and rate me accordingly .
Else you can further questions here .
Thankyou

sir but you might be swapping the data?
How to swap nodes?

No i am not swapping the data you have to change the links to reverse the LL .
For 2 nodes
we can reverse it as :-
head->next->next = head ;
head->next = NULL;

Now the new head for the reversed LL will be head->next .
I hope now you get my point . Feel free to ask if you have any other query