-
×InformationFix Windows 10 Update Issues
Resolve Windows 10 related issues for your HP computers or printers by HP Windows 10 Support Center
-
-
×InformationFix Windows 10 Update Issues
Resolve Windows 10 related issues for your HP computers or printers by HP Windows 10 Support Center
-
- HP Community
- >
- Other Products
- >
- Calculators
- >
- How to do "selection sort" in HP 50g graphing calculator by ...
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

Create an account on the HP Community to personalize your profile and ask a question

How to do "selection sort" in HP 50g graphing calculator by using User RPL
04-06-2020 05:09 AM

Hi dear HP Community ,
I want to know how to do selection sort in
HP 50g graphinc calculator without using SORT function ( or maybe command ) or without using built in - hidden commands such as #2FD006h FLASHEVAL or others.
Let's suppose that I have a unsorted list like this { 1 5 2 4 3 2 8 2 4 } and I want to order those elements by ther values from biggest to smallest or vice versa , whatever.
I want to know how to do that by using clean User RPL ,
if also possible ... if not possible let me know about that. I also found some literature for doing selection sort .
Also this is from wikipedia :
https://en.m.wikipedia.org/wiki/Selection_sort
And also i have material from Geeks for Geeks site how to do this on well known programming languages like C , C++ , Java , Python etc..
https://www.geeksforgeeks.org/selection-sort/
Besides all of that i also post a question on HP Support Community about sorting , mister Horn replied to me and i think that he gave me useful advices but still i don't know how to do these things and how to use that knowledge for solving this - selection sort.
I don't know dear people but I will be very very gratefull if someone knows how to do that because no one replied to me about that when i wrote that I don't know how to do that - I'm thinking about selection sort in HP 50g graphing calculator ( User RPL ).
Best regards ,
Bye 🤗
04-15-2020 08:40 PM

Ok, here's what you were looking for: A 100% standard User RPL program which uses stack operations to sort a list of numbers using the Insertion Sort algorithm, optimized with a binary search. Two local variables are used, one to store the size of the original list, and one as the counter in the FOR-NEXT loop. In a nutshell, the list is exploded onto the stack, then all the sorting is performed on the stack, and when the stack is all sorted, the numbers on the stack are placed back into a list. Therefore, while the work of sorting is being performed, there are no lists or arrays of any kind either on the stack nor stored in a variable.
Input: List of numbers.
Output: Same list, sorted into ascending order.
Speed: Sorts 128 random reals in 9 seconds; 128 random integers in 35 seconds.
This program is useful only for study purposes, since the built-in SORT command (which uses the same logic as this program) is roughly 8 times faster.
« OBJ→ → s « 1. s FOR j s ROLL 0. j
WHILE DUP2 SWAP – 2. / IP DUP
REPEAT OVER SWAP – DUP 4. + PICK 5. PICK
IF > THEN UNROT END SWAP DROP
END ROT DROP2 ROLLD NEXT s →LIST » »
Didn't find what you were looking for? Ask the community