Swap every consecutive elements in Linked list

You have single linkedlist.Swap every consecutive two elements without using value stored in the node of linkedlist. for eg. 1->2->3->4->5 then output should be 2->1->4->3->5

Comments

  1. struct node* swaptwo(struct node *head)
    {
    if((head!=NULL)&&(head->link !=NULL))
    {
    struct node *tmp1=head->link->link;
    struct node *tmp2=head->link;
    head->link->link=head;
    head->link=swaptwo(tmp1);
    return tmp2;

    }
    else return head;

    }

    ReplyDelete

Post a Comment

Popular posts from this blog

Circular game survival