Sort (structured) Linked list via multiple fields

Just starting out? Need help? Post your questions and find answers here.
freak
PureBasic Team
PureBasic Team
Posts: 5940
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

Since PB 4.30, SortStructuredList (and SortList) use Mergesort which is a stable sort, so if you first sort all the list by titles and then again by album you will get a list which is sorted by album and each album is sorted by title.

Note that this does not work with Arrays, as SortArray uses Quicksort which is unstable. (ie the sorting of the secondary key would be lost)
quidquid Latine dictum sit altum videtur
akj
Enthusiast
Enthusiast
Posts: 668
Joined: Mon Jun 09, 2003 10:08 pm
Location: Nottingham

Post by akj »

@ freak:

Please add to the Help documentation for SortStructuredList() and SortList() that they are stable sorts.

Is there any chance in the future for the other sort routines to have a stable sort option in addition to the standard method?
Anthony Jordan
technicorn
Enthusiast
Enthusiast
Posts: 105
Joined: Wed Jan 18, 2006 7:40 pm
Location: Hamburg

Post by technicorn »

@akj

It's not possible to use Mergesort for arrays, because Mergesort can't work in place, that means the array would have to be taken apart and then put back together again.

With lists you can use the already existend link headers of the list to do it.

For more in depth explanation use google and search for "Mergesort wiki"
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

But it's possible to make a stable quicksort.
Little John
Addict
Addict
Posts: 4779
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Post by Little John »

technicorn wrote:It's not possible to use Mergesort for arrays, because Mergesort can't work in place, that means the array would have to be taken apart and then put back together again.
It is possible to use Mergesort for arrays, of course.

Regards, Little John
Post Reply