Post Reply 
(42S) Matrix Sort
07-05-2018, 06:08 PM (This post was last modified: 07-05-2018 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 (1-based)

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 1-row matrix will exit cleanly without doing anything.

EDIT: A nicer version that uses the built-in (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"
RDown
STO "_D"
RDown
STO "_Z"
RDown
STO "_T"
RDown
INDEX "_D"
1
X<>Y
STOIJ
LBL 00
RCLIJ
X<>Y
FC? 01
XEQ "[MIN]"
FS? 01
XEQ "[MAX]"
RDown
R<>R
I+
FC? 76
GTO 00
RCL "_T"
ENTER
ENTER
RCL "_Z"
RCL "_D"
CLV "_M"
CLV "_R"
CLV "_D"
CLV "_Z"
CLV "_T"
END
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
(42S) Matrix Sort - Dave Britten - 07-05-2018 06:08 PM
RE: (42S) Matrix Sort - Joe Horn - 07-05-2018, 08:16 PM
RE: (42S) Matrix Sort - Dave Britten - 07-05-2018, 08:28 PM
RE: (42S) Matrix Sort - Joe Horn - 07-05-2018, 09:17 PM
RE: (42S) Matrix Sort - Dave Britten - 07-05-2018, 09:27 PM
RE: (42S) Matrix Sort - Joe Horn - 07-05-2018, 10:21 PM



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