(42S) Matrix Sort

07052018, 06:08 PM
(This post was last modified: 07052018 09:32 PM by Dave Britten.)
Post: #1




(42S) Matrix Sort
A simple program for sorting a matrix by your choice of column, in either ascending or descending order.
Usage Arguments: y: Matrix x: Column number (1based) Flag 1: Clear = Ascending Order, Set = Descending Order Put the arguments on the stack and XEQ "SORT". The sorted matrix will be left on the stack in x. Attempting to sort a 1row matrix will exit cleanly without doing anything. EDIT: A nicer version that uses the builtin (hidden) "[MIN]" and "[MAX]" functions to do selection sort. When keying this in, note that the brackets are part of the function name and must be included! I've written that function as XEQ "[MIN]" for clarity, but you'll only see [MIN] after entering the command. Thanks Joe. Code: LBL "SORT" 

07052018, 08:16 PM
Post: #2




RE: (42S) Matrix Sort
For a much faster sort (and probably a shorter program), combining the "hidden" [MIN] and [MAX] functions built into the HP42S with the R<>R function allows rapid sorting of the rows in a matrix into ascending or descending order using any desired column as the sorting key.
<0ɸ0> Joe 

07052018, 08:28 PM
Post: #3




RE: (42S) Matrix Sort
(07052018 08:16 PM)Joe Horn Wrote: For a much faster sort (and probably a shorter program), combining the "hidden" [MIN] and [MAX] functions built into the HP42S with the R<>R function allows rapid sorting of the rows in a matrix into ascending or descending order using any desired column as the sorting key. Ah, I didn't realize the hidden MIN and MAX functions were columnspecific and could have a starting point specified like that. That would make for a pretty easy selection sort implementation, and while that's the same complexity class as bubble sort, having MIN doing all the heavy lifting in the innermost loop would probably improve performance. I'll have to take a stab at that later this evening. Half the reason I post things in the software library is because somebody undoubtedly knows some clever functions/tricks that I can learn about to make the program better. 

07052018, 09:17 PM
(This post was last modified: 07052018 09:19 PM by Joe Horn.)
Post: #4




RE: (42S) Matrix Sort
Yikes, I just tried to write it up using Free42, and [MAX] and [MIN] don't seem to be in it! Is there some secret way to get to those functions in Free42, or are they really missing?
EDIT: Please note that the [MIN] and [MAX] functions are spelled exactly that way, including the brackets. <0ɸ0> Joe 

07052018, 09:27 PM
Post: #5




RE: (42S) Matrix Sort
(07052018 09:17 PM)Joe Horn Wrote: Yikes, I just tried to write it up using Free42, and [MAX] and [MIN] don't seem to be in it! Is there some secret way to get to those functions in Free42, or are they really missing? What version are you running? They're definitely in there on 2.0.20, which is the current DM42 version. I did XEQ "[MIN]" and it worked fine. 

07052018, 10:21 PM
(This post was last modified: 07052018 10:27 PM by Joe Horn.)
Post: #6




RE: (42S) Matrix Sort
(07052018 09:27 PM)Dave Britten Wrote: What version are you running? They're definitely in there on 2.0.20, which is the current DM42 version. I did XEQ "[MIN]" and it worked fine. Aha! I don't know which version I had (possibly an ancient one), but the App Store right now is updating me to version 2.0.21. Thanks! EDIT: Yay! It works! <0ɸ0> Joe 

« Next Oldest  Next Newest »

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