Post Reply 
(35S) Quicksort on the HP 35s
06-20-2021, 02:14 PM (This post was last modified: 06-20-2021 08:12 PM by Gene.)
Post: #1
(35S) Quicksort on the HP 35s
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.


Attached File(s)
.pdf  HP35sQuickSort.pdf (Size: 23.62 KB / Downloads: 23)
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)