Sorting linked lists
Richard Harter
g-rh at cca.UUCP
Tue Mar 18 16:08:17 AEST 1986
In article <> chris at umcp-cs.UUCP (Chris Torek) writes:
>In article <165 at ablnc.UUCP> rcpilz at ablnc.UUCP writes:
>
>>I would like to know if there is a way to sort a linked list.
>
>You get to roll your own. I started to think about this, and blew
>a couple of hours writing the code below......
A simpler method, given qsort with a compare function as an
argument, is to create an array of pointers to the nodes and
write the appropriate compare routine to compare the keys being
pointed at. Qsort then shuffles the pointers around to produce
the sorted list. You can then relink the list in sorted order
using the array of pointers.
Richard Harter, SMDS Inc.
More information about the Comp.lang.c
mailing list