Pregunta de entrevista de Bloomberg

How would you print a linked list in reverse order?

Respuestas de entrevistas

Anónimo

3 mar 2011

@blakdogg: The question is not about how to reverse the link list but to print it in reverse. Here is my solution: void reversePrint(Node* current) { if (current) { reversePrint(current->next); printf ("%s \n", current->data); } }

8

Anónimo

5 nov 2011

Jon: Your solution would crash on a large data set. Too much stack space used. The first solution was a hint at the overall solution which would be to use that function twice. Once to reverse the list, then print, then reverse it back.

2

Anónimo

17 ene 2013

void printReverseLinkedList (Node node) { if (node.next != null) { printReverseLinkedList(node.next); } System.out.println(node.data); }

1

Anónimo

18 feb 2011

public Node reverseList(Node root) { Node rev = root; Node current;// = root; Node fwd = root.left; rev.left=null; while (fwd!=null) { current = fwd; fwd=current.left; current.left=rev; rev=current; } return rev; }

1