Goldman Sachs Interview Question

How do you reverse a linked list? Write the code.

Interview Answer

Anonymous

Jul 31, 2009

void reverse(node** head) { node* cur = *head; *head = null; while (cur) { node* next = cur->next; cur->next = *head; *head = cur; cur = next; } }

4