Jun 22, 2009

Reverse the linked list, recursively, tail-recursive:

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);
}

No comments:

Post a Comment