struct node * Rec_Reverse(struct node *p, struct node *q)
{
static struct node *r;
if(q->next!=NULL)
Rec_Reverse(p->next,q->next);
if(set == 0)
{r=q;
set++;
}
q->next = p;
p->next=NULL;
return r;
}
This method has to be invoked as
list = Rec_Reverse(list, list->next);
The pointer to the reversed list is 'r'.
On Sat, Jul 30, 2011 at 8:11 PM, bharath sriram <[email protected]>wrote:
> Can anyone give the recursive version of reversing a linked list. Please
> post the reverse function code snippet and not the entire .c file since it
> just hampers readability.
>
> Bharath.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
--
Regards,
Vanathi
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.