After doing recursion the 1 is getting passed as head in last but 4 should be passed. How it is returning 4 as head here?
How does new head gets returned?
Hello @shivammishra2408 1 2 3 is the linked list then in it according to the resusion call the nest part of the 1 will be null and for 2 it will be 1 and for 3 it will be 2 and we will declare the as head.
if you have any further doubt you can ask here:
Happy Learning!!
My question is regarding reversing a linked list using recursion. Please watch the last part of the video of the same if possible. 4->null then returns then 3 becomes head and it becomes 4->3->null and ultimately it returns with 1 as head. Whereas the linkedlist formed is now: 4->3 ->2->1->null. It should have returned 4 as head but the answer is coming right.
Hello @shivammishra2408 there in the video they must have declared the new pointer and which they must be saving the head by recursion you are doing the dry run wrong.
they are returning 4 as the head that is why only the answer is right.
Happy Learning!!
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.