int reverse(node * tmp)
{
static int i;
// cout<<i<<" ";
i++;
if(tmp==NULL)
{
return 0;
}
if((tmp->next)==NULL)
{
head=tmp;
i--;
return 0;
}
if((tmp->next)!=NULL)
{
reverse(tmp->next);
(tmp->next)->next=tmp;
i--;
if(i==0)
{
tmp->next=NULL;
tail=tmp;}
return 0;
}
return 0;
}
On Sun, Jul 17, 2011 at 2:42 PM, Navneet Gupta <[email protected]>wrote:
> Hi,
>
> I was trying to accomplish this task with the following call , header
> = ReverseList(header)
>
> I don't want to pass tail pointer or anything and just want that i get
> a reversed list with new header properly assigned after this call. I
> am getting issues in corner conditions like returning the correct node
> to be assigned to header.
>
> Can anyone give an elegant solution with above requirement? Since it
> is with recursion, please test for multiple scenarios (empty list, one
> node list, twe nodes list etc) before posting your solution. In case
> of empty list, the procedure should report that.
>
> --
> Regards,
> Navneet
>
> --
> 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.
>
>
--
Ankur Khurana
Computer Science , 4th year
Netaji Subhas Institute Of Technology
Delhi.
--
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.