Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site cca.UUCP Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!genrad!decvax!cca!g-rh From: g-rh@cca.UUCP (Richard Harter) Newsgroups: net.lang.c Subject: Re: Sorting linked lists Message-ID: <6721@cca.UUCP> Date: Tue, 18-Mar-86 01:08:17 EST Article-I.D.: cca.6721 Posted: Tue Mar 18 01:08:17 1986 Date-Received: Fri, 21-Mar-86 04:23:24 EST References: <165@ablnc.UUCP> <> Reply-To: g-rh@cca.UUCP (Richard Harter) Organization: Computer Corp. of America, Cambridge Lines: 16 In article <> chris@umcp-cs.UUCP (Chris Torek) writes: >In article <165@ablnc.UUCP> rcpilz@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.