Pergunta de entrevista da empresa Yahoo

how to print a singly linked list backwards

Respostas da entrevista

Sigiloso

17 de jul. de 2014

void reverseList(Node head) { //Base case if(head == null) return; reverseList(head.next); System.out.print(head.data); }

1

Sigiloso

5 de set. de 2014

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

1

Sigiloso

5 de out. de 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.