Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/5/84; site bunker.UUCP Path: utzoo!watmath!clyde!burl!ulysses!bellcore!decvax!ittatc!bunker!shap From: shap@bunker.UUCP (Joseph D. Shapiro) Newsgroups: net.lang.c Subject: Re: Sorting linked lists Message-ID: <1104@bunker.UUCP> Date: Mon, 17-Mar-86 17:20:19 EST Article-I.D.: bunker.1104 Posted: Mon Mar 17 17:20:19 1986 Date-Received: Tue, 18-Mar-86 08:45:37 EST References: <165@ablnc.UUCP> Reply-To: shap@bunker.UUCP (Joseph D. Shapiro) Organization: Bunker Ramo, Trumbull Ct Lines: 42 Keywords: Sort link-list Summary: In article <165@ablnc.UUCP> rcpilz@ablnc.UUCP (Robert C. Pilz) writes: > > >I would like some advice on sorting linked lists. I >am running SVR2 UNIX on a VAX 11/780 and 3B20S. I >would like to know if there is a way to sort a linked list. >I know that a table can be sorted via qsort(3c). But >it assumes that every element is contiguous in memory. >In a linked list this is not the case. Do I do a >memory copy of some type to get the link list contiguous? >I would like to know what works. > >Send replies to: >ihnp4!abfll!rcpilz >Thanks try the following: traverse your linked list, making an array of pointers to each node. write a comparison routine to compare two nodes, given two pointers to pointers to nodes. use qsort to sort your array of pointers to nodes. traverse the array of pointers to nodes, re-writing the links in the nodes as you go. hope this helps -- -_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_ Joseph D. Shapiro "He who hesitates Bunker Ramo Information Systems is lunch" {bellcore, genrad, mcnc, sunybcs}\ {harpo, linus, decwrl, tektronix}->!decvax!ittvax!bunker!shap {dartvax, ucbvax, wanginst, yale}/ sdcsvax!dcdwest!ittvax!bunker!shap