Jump Trading interview question

Reverse a link list without using loops?

Interview Answers

Anonymous

5 Dec 2012

Use recursion.

2

Anonymous

25 Oct 2015

void reverseList(List* list, Node* cur, Node* next, Node* prev) { if (next == NULL) { cur->next = prev; list->head = cur; return; } cur->next = prev; reverseList(list, next, next->next, cur, i); } void reverse(List* list) { reverseList(list, list->head, list->head->next, NULL); }