Sort Routine

Author(s): Leo Morgan
Publication: Syntax
Pub Details: Syntax/Syntax ZX80 v2 n10 (Volume 2, Issue 10)
Date: October 1981
Pages: 15

This 8K/1K routine can sort 20 words of 20 characters in about 8 seconds. This program was originally an Apple sort program but required major revisions to run on the ZX80.

If you use it to order numbers, make sure they have the same number of digits, filling in leading zeros if necessary. Spaces between letters will be considered in the sort. The ZX80 gives numerical values to letters and numbers. For example, A is less than B. A space is less than any letter.

Line 200 allows the program to be saved on tape. Just type RUN 200 to save. To load, type LOAD “SORT”. The program will come up ready to run. To exit at the end of program, type (NL). To exit during a sort, type BREAK (NL).

   1 REM ALPHA-NUMERIC SORT ROUTINE REVISED BY LEO MORGAN 9/5/81
5 PRINT "ENTER NUMBER OF WORDS, 1 TO N"
10 INPUT N
15 DIM A$(N,20)
20 FOR I=1 TO N
25 PRINT "TYPE A WORD, 1 TO 20 CHARACTERS"
27 PRINT AT 21,0;I
30 INPUT A$(I)
35 CLS
40 NEXT I
50 LET X=0
60 LET X=X+1
70 IF X>N THEN STOP
80 IF A$(X)="ZZZZZZZZZZZZZZZZZZZZ" THEN GOTO 60
90 FOR Y=1 TO N
100 IF A$(Y)<A$(X) THEN LET X=Y
110 NEXT Y
120 PRINT A$(X)
130 LET A$(X)="ZZZZZZZZZZZZZZZZZZZZ"
140 GOTO 50
200 SAVE "SORT"
210 GOTO 5
Syntactic Sum: 24438, 8K

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.