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

Ask a Question

 

Start Coding Today

   

GeeksQuiz

GeeksforGeeksIDE

Data Structures

Algorithms

Interview Experiences

C Programming

C++ Programming

Java Programming

GATE CS

Books

Reversing LikedList Recursion

Hey, below is the method for Reversing LinkedList.

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

As per the recursion model, all method calls will be pushed and later popped. So, the popping starts when head.next 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
...