TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: MATHIEU BOUCHARD
from: DARIN MCBRIDE
date: 1998-03-27 19:51:00
subject: Sorting linked list

 TF>> How do i (quick)sort linked lists?
 DM> Quick sort requires random access which lists don't have.  
 MB> I don't know what your quicksort is, but mine doesn't require random
 MB> access. I would still use an array version instead of a list version
 MB> cause i'm lazy, however, i can write a linked list version that won't
 MB> be *that* slow (i mean, it won't be anymore than O(n log n)).
 MB> Write your quicksort algorithm and i'll see why it can't be applied to
 MB> lists...
Quicksort, by definition, requires random access.  Many methods, such as 
insertion sort, IIRC, can use bidirectional access (being able to move 
forward and backward one at a time) or even unidirectional access (although 
usually at the cost of increased stack space).  Quicksort needs to be able to 
quickly find arbitrary nodes and swap them.
And I think quicksort has O(log n) timing, unless I'm already forgetting the 
standard timings.  :-)  If I'm right, that's a major difference in speed 
between nlgn and lgn.
---
---------------
* Origin: Tanktalus' Tower BBS (1:250/102)

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™.