TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: BILL GODFREY
from: TIM HUTZLER
date: 1998-03-28 21:04:00
subject: Re: Sorting linked list

TF>>How do i (quick)sort linked lists?
TH>Collect the pointers into an array. Sort the pointers using whatever key
TH>you wish to sort by. Then build a new linked list. ___ Blue Wave/QWK
BG>I would recommend forgetting a quick sort, and just re-build a
BG>copy of the linked list in sorted form.
But, *how* do you sort it?
BG>The main nice feature about linked lists is the ability to insert
BG>items with the minimum of fuss.
True, but that has nothing to do with sorting. Whether its a linked
list, or an array - some sort of sorting algorithm will have to be
employed.
BG>Even better, sort the list stright away as you add items in.
BG>Insert them in the right place to start with. (That is, if it's
BG>appropiate to do so).
It's still sorting, and not very effient. The list will have to be
scanned for each insertion. Average efficiency would be N/2 for
insertion and deletion. I binary tree would be more effient, Big 'O'
would be log N for both ways.
___ Blue Wave/QWK v2.12
--- Maximus/2 3.01
---------------
* Origin: Madman BBS * Chico, California * 530-893-8079 * (1:119/88)

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