GfG QA is closing soon... Please refer PRACTICE or GfG now on wards !!

Reversing LikedList Recursion

Hey, below is the method for Reversing LinkedList.

public ListNode reverseList(ListNode head) {
if (head == null || == null) return head;
ListNode p = reverseList(; = head; = null;
return p;

As per the recursion model, all method calls will be pushed and later popped. So, the popping starts when will be null and head will be pointing to last node. That's fine....

So, the below method calls where the actual reversing will happen, is returning some pointer 'p'. What will happen then?

asked Jul 5, 2016 by anonymous