Reverse a linked List using recursion, by using one argument only
list * rev(list *head)
{
if(head==NULL)
return NULL;
if(head->next==NULL)
return head;
list *tail=rev(head->next);
head->next->next=head;
head->next=NULL;
return tail;
}
Node* rev(node* head)
{
Node* curr=head, *pr=null, *next;
While(curr)
{
Next=curr->next;
Curr->next=pr;
Pr=curr;
Curr=next;
}
Return pr;
}
Feb 25, 2009
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment