Reverse the linked list, recursively, tail-recursive:
node *reverse(node *head, node *pre ) {//initially node* pre=null
if (!head) return NULL;
If(!head->next) {head->next=pre; return head;}
node *next = head->next;
head->next = pre;
return reverse(next, head);
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment