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

Explain what is the benefit of using const for declaring constants?

0 Answers  


Given an unsigned integer, find if the number is power of 2?

5 Answers  


What are integer variable, floating-point variable and character variable?

0 Answers  


How can I discover how many arguments a function was actually called with?

0 Answers  


What does calloc stand for?

0 Answers  






accept character from keyboard untill the user presses the enter key.If the user enters any character other than upper case(A-Z)alphabets program should stop taking any input

1 Answers  


main() { charx; while (x=0;x<=255;x++) printf("\nAscii value %d Character %c,x,x); }

2 Answers  


Explain how can I avoid the abort, retry, fail messages?

0 Answers  


What are the Advantages of using macro

0 Answers  


What is output of the following program ? main() { i = 1; printf("%d %d %d\n",i,i++,i++); }

9 Answers   CTS, Wipro,


Can we include one C program into another C program if yes how?

7 Answers   Infosys,


Explain the advantages and disadvantages of macros.

0 Answers   TCS,


Categories