Jump Trading Interview Question

Reverse a link list without using loops?

Interview Answers

Anonymous

Dec 5, 2012

Use recursion.

2

Anonymous

Oct 25, 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); }