Interview Question

Software Engineer Interview San Jose, CA

how to print a singly linked list backwards


Interview Answer

3 Answers


void reverseList(Node head)
     //Base case
     if(head == null)

Mahe on Jul 17, 2014

Populate the content of the linked list onto a stack. Pop each element of stack and print it.

Anonymous on Sep 4, 2014

Yeap , both the above answers are almost the same. The recursive call works in the stack way. Whenever a recursive call is made, the current data are pushed into a stack and when the recursion recoils, data is popped and processed accordingly from the stack.

Muthu on Oct 5, 2014

Add Answers or Comments

To comment on this, Sign In or Sign Up.