Sorting Double Linked List in place
michelle krill of yore lee
mikey at ontek.com
Sat Nov 10 05:17:19 AEST 1990
In comp.lang.c, anton at analsyn.UUCP (Anton Aylward) writes:
| I'm looking for a routine to sort a double linked list in place,
| given the head of the list and a compare function for the elements
| (sort of like qsort).
|
| I've seen single link sorts that use auxillary 'bins" (kind of like
| merge tape sort), but I'm convinced ther is something more efficient
| for the DLL, since there is the extra link.
|
| References or sample algorithm anyone ?
What I always do is count how big the list is, malloc an array
of pointers, initialize the array to point to each thing on the
list, call qsort on the array, relink the list based on what
comes back from qsort, and then free the array. This consists of
two passes + whatever length of time qsort takes. Now you have
a sorted, doubly linked list.
the krill, or was that obvious?
More information about the Comp.lang.c
mailing list