A short demonstration of the bubble sort for the 1K ZX80. Lines 1 to 50 fill an array with random numbers from 1 to 100. The program prints ten of them on one line, sorts them into ascending order with the routine that starts at line 200, then prints the sorted numbers underneath and stops. RUN again for a new set.
The sort routine can be used on its own in your programs. The article suggests sorting words the same way by coding the letters as the numbers 1 to 26. Line 30 fills eleven elements, A(0) to A(10), but only the first ten are printed and sorted.
Syntax left the author’s name off the article; the February 1981 issue credited Robert J. Schlesinger of Van Nuys, CA.
Published in Syntax January 1981 (Bubble Sort Routine).
Source Code
1 REM * SET UP DIM ARRAY
10 DIM A(10)
30 FOR R=0 TO 10
43 LET S=RND(100)
45 LET A(R)=S
50 NEXT R
100 REM * PRINT OUT ROUTINE
105 LET P=0
107 LET X=0
110 PRINT A(X);" ";
115 LET X=X+1
120 IF X=10 THEN GO TO 150
130 IF X<10 THEN GO TO 110
150 LET P=P+1
160 IF P=2 THEN GO TO 300
190 REM **** BUBBLE SORT ROUTINE
200 FOR I=0 TO 10
210 LET J=9
220 IF A(J-1)<A(J) THEN GO TO 260
230 LET Y=A(J-1)
240 LET A(J-1)=A(J)
250 LET A(J)=Y
260 LET J=J-1
270 IF J>I THEN GO TO 220
280 NEXT I
290 GO TO 107
300 STOPNote: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.

