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

You have an array of n integers, randomly ordered with value 1 to n-1.The array is such that there is only one and one value occurred twice. How will you find this number?

1 Answers  


Should I learn c before c++?

0 Answers  


What is the difference between macros and inline functions?

5 Answers   Global Edge, L&T,


a linear linked list such that the link field of its last node points to the first node instead of containing NULL a) linked list b) circular linked list c) sequential linked list d) none

0 Answers  


Is main() is used in the program,,see below example? void main() { int i; for(i=0;i<10;i++) main(); } Then what is the output of the program?

6 Answers  






How would you obtain the current time and difference between two times?

0 Answers   TISL,


What is the output of the following program main();{printf ("chennai""superkings"}; a. Chennai b. superkings c. error d. Chennai superkings

6 Answers  


Write a program to implement a round robin scheduler and calculate the average waiting time.Arrival time, burst time, time quantum, and no. of processes should be the inputs.

0 Answers   Aspiring Minds,


program to print upper & lower triangle of a matrix

2 Answers   TCS,


Main must be written as a.the first function in the program b.Second function in the program c.Last function in the program d.any where in the program

19 Answers   CTS, HCL, TCS,


What is c basic?

0 Answers  


Write a C program to count the number of email on text

0 Answers  


Categories