Have a look at this recursive soln in java -

Node convertList(Node head)
        {
                if(head ==null)
                        return null;
                
                Node node = head;
                Node next = node.next;
                Node next2next = next.next;
                
                next.next = node;
                node.next = convertList(next2next);
                
                return next;
        }

This soln assumes even number of nodes in the list. The code is quite
self explanatory.

--Anurag


On Wed, Jun 1, 2011 at 6:26 AM, Anand <[email protected]> wrote:
> Given a linked list of the form, 1->2->3->4->5->6, convert it into the form
> 2->1->4->3->6->5. Note that the nodes need to be altered and not the data
> contained in them
>
> --
> 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.
>

-- 
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.

Reply via email to