Skip to content

Instantly share code, notes, and snippets.

@James-Livesey
Created June 26, 2025 21:16
Show Gist options
  • Save James-Livesey/0e62609a3b0131513c40733b881c0690 to your computer and use it in GitHub Desktop.
Save James-Livesey/0e62609a3b0131513c40733b881c0690 to your computer and use it in GitHub Desktop.
Record sorting algorithm demo for the Psion Organiser II (public domain — CC0)
SORT:
LOCAL A%,B%,I%
REM Set up file
IF EXIST("A:LIST")
DELETE "A:LIST"
ENDIF
CREATE "A:LIST",A,V%
REM Get items (0 to end)
WHILE 1
PRINT "ENTER ITEM: ";
INPUT A.V%
IF A.V%=0
BREAK
ENDIF
APPEND
ENDWH
REM Main sorting algorithm
FIRST
WHILE 1
REM Get A% and B% values
A%=A.V%
NEXT
IF EOF
BREAK
ENDIF
B%=A.V%
BACK
IF A%>B% :REM Value comparison
UPDATE
FIRST
ELSE
NEXT
ENDIF
REM Display current iteration
SORTSHOW:
PRINT "POS ";POS;" ITER ";I%
PAUSE 10
I%=I%+1
ENDWH
REM Display final result
SORTSHOW:
PRINT "DONE ";I%;" ITERS"
GET
SORTSHOW:
LOCAL P%
P%=POS
FIRST
CLS
WHILE NOT EOF
PRINT A.V%;" ";
NEXT
ENDWH
PRINT
POSITION P%
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment