Basic and Advance C Question:
Download Questions PDF

How can I sort a linked list?

Answer:

Sometimes it's easier to keep the list in order as you build it (or perhaps to use a tree instead). Algorithms like insertion sort and merge sort lend themselves ideally to use with linked lists. If you want to use a standard library function, you can allocate a temporary array of pointers, fill it in with pointers to all your list nodes, call qsort, and finally rebuild the list pointers based on the sorted array.

Download C Programming Interview Questions And Answers PDF

Previous QuestionNext Question
How can I sort more data than will fit in memory?How can I get the current date or time of day in a C program?