238. You have single linkedlist.Swap every consecutive ... .....
Microsoft Interview Questions and Answers
(Continued from previous question...)
238. You have single linkedlist.Swap every consecutive ... .....
Question:
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
maybe an answer:
/*Swap every consecutive two elements without using value stored in the node of linkedlist
use*/
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;
}
(Continued on next question...)
Other Interview Questions
|