You are viewing a single comment's thread. Return to all comments →
The recursive solutions presented here are not tail recursive. If you wish to use recursion then an auxiliary tail recursive function should be used:
Node* ReverseTR(Node *X, Node *Y) { Node *t; if (X == NULL) { return Y; } else { t = X->next; X->next = Y; return ReverseTR(t, X); } } Node* Reverse(Node *head) { return ReverseTR(head, NULL); }
Reverse a linked list
You are viewing a single comment's thread. Return to all comments →
The recursive solutions presented here are not tail recursive. If you wish to use recursion then an auxiliary tail recursive function should be used: