TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: TIMO FINNIL
from: ANDREW FRANK
date: 1998-03-21 00:02:00
subject: Re: Sorting linked list

As Timo Finnil had made known to All, on 18 Mar 98  21:17:48, I quote.
 TF> Help me please, i got a big problem %-)
 TF> How do i (quick)sort linked lists?
 Ouch!  You do have a big problem.  There isn't a way to quick sort a linked 
list directly, but here's what I'd do:
 1) traverse the list, and count the elements
 2) allocate an array of pointers to point to each element
 3) fill the array by traversing the list again, and copying the pointers 
into the array.
 You should now have an array where each element points to each entry in the 
linked list.
 4) perform a pointer based quick sort on the array, where use the pointers 
to compair items, and switch them by switching pointers.
 5) write the pointers in the array back into the pointers in the linked 
st.
 Actually, this should be faster than an array based quick sort as the data 
doesn't have to be moved, only pointers.  Just a bit of a pain.
... Incoming fire has the right of way.
--- Blue Wave/386 v2.30 [NR]
---------------
* Origin: fks Online! * Mississauga, ON Canada (1:259/423)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.