HP Forums
(35S) Quicksort on the HP 35s - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Software Libraries (/forum-10.html)
+--- Forum: General Software Library (/forum-13.html)
+--- Thread: (35S) Quicksort on the HP 35s (/thread-17142.html)



(35S) Quicksort on the HP 35s - arhtur - 06-20-2021 02:14 PM

Another algorithm I wanted to try implementing on an HP calculator is the Quick Sort. This is based on a public domain C implementation by Darel Rex Finley.

B=begin index (starts at register 210)
E=end index (starts at register 270)
L=left pointer
R=right pointer
P=pivot point
K=loop index

This sort algorithm (see attached .PDF file) is initially set to sort 30 items (in line Q012), but can be increased to 100.

Unsorted numbers are in registers 0 to 29.

Do XEQ F000 to fill registers 0 to 29 with random numbers (0 to 98).

You can XEQ Q141 to display the random elements. Press R/S repeatedly until you have viewed the last element (29).

Then XEQ Q001 to run the quicksort.

XEQ Q141 again to view the sorted numbers and press R/S repeatedly, until you reach the last element (29).

If you run Quicksort again on an already sorted set of numbers, the algorithm may fail, since the pivot point is not ideal. There is also no error checking if the begin or end array overruns its bounds (60 elements for each is allocated, which is just over half, if there are 100 elements). I also have a HP 42s version, if anyone is interested.