HP 35s Bubble Sort - Printable Version +- HP Forums (https://archived.hpcalc.org/museumforum) +-- Forum: HP Museum Forums (https://archived.hpcalc.org/museumforum/forum-1.html) +--- Forum: Old HP Forum Archives (https://archived.hpcalc.org/museumforum/forum-2.html) +--- Thread: HP 35s Bubble Sort (/thread-146887.html) |
HP 35s Bubble Sort - Elliott W Jackson - 02-14-2009 The Wiki site claims the Gnome Sort to be the simplest, but it turns out that converting the Bubble Sort to HP GTO-ese is actually simpler, and has faster run times too. Pseudo code:
procedure bubbleSort( A : list of sortable items ) defined as: Program listing:
S001 LBL S And finally, some timings:
21 registers, 10.030: 23 seconds
So, even the much-detested Bubble Sort is superior to the cutesy Gnome Sort I started this project with.
Re: HP 35s Bubble Sort - Marcus von Cube, Germany - 02-14-2009 Bubble sort isn't bad, if the items are "in almost sort order" at the beginning of the algorithm. If all items are already sorted, a single pass is all to find that out. Bubble sort is stable, too, that is, it leaves the original sorting of items considered "equal" by the comparison algorithm intact.
|