Wednesday, January 23, 2013

Write a program that reverses alternate elements in a given linked list input: a->b->c->d->e, output should be b->a->d->c->e

Node reverseAlterante ( Node head) {
if ( head == null || head.next == null )
return head;
Node r = reverseAlternate(head.next.next);
Node t = head.next ;
t.next = head;
head.next = r;
return t ;
}

No comments:

Post a Comment