Question d’entretien chez Google

How would you reverse a linked-list?

Réponses aux questions d'entretien

Utilisateur anonyme

3 oct. 2011

http://www.teamten.com/lawrence/writings/reverse_a_linked_list.html Element *reverse(Element *head) { Element *previous = NULL; while (head != NULL) { // Keep next node since we trash // the next pointer. Element *next = head->next; // Switch the next pointer // to point backwards. head->next = previous; // Move both pointers forward. previous = head; head = next; } return previous; }

1

Utilisateur anonyme

5 oct. 2011

Good explanation in the comments.

Utilisateur anonyme

31 oct. 2011

There are detailed analysis and solution in the blog: http://codercareer.blogspot.com/2011/10/no-18-reverse-linked-list.html