How would you sort a linked list?



How would you sort a linked list?..

Answer / prakashdasari

node *ptr1,*ptr2,*ptr3;
ptr1=start;
ptr2=ptr1->next;
ptr3=ptr2->next;
ptr1->next=NULL;
ptr2->next=ptr1;
while(ptr3!=NULL)
{
ptr1=ptr2;
ptr2=ptr3;
ptr3=ptr3->next;
ptr2->next=ptr1;
}
start = ptr2;

Is This Answer Correct ?    1 Yes 2 No

Post New Answer

More C Interview Questions

Why pointers are used in c?

0 Answers  


how to make a scientific calculater ?

0 Answers  


Why we use break in c?

0 Answers  


What is the scope of static variable in c?

0 Answers  


extern static int i func() { i =10; i++; printf("%d \n",i); } main() { i =20; printf("%d \n",i); func(); printf("%d \n",i); }

2 Answers  






What is ctrl c called?

0 Answers  


Explain the difference between the local variable and global variable in c?

0 Answers  


What is the difference between the local variable and global variable in c?

0 Answers  


Why doesnt this code work?

0 Answers  


what does exit() do?

3 Answers   Cadence,


What are two dimensional arrays alternatively called as?

0 Answers  


Here is alphabets : abcdefgh 1) how to reverse. as hgfedcba 2) after reversal, how to group them in a pair hg fe dc ba.

2 Answers  


Categories