Jump Sort

Author(s): Gene G. Buza
Publication: Synchro-Sette
Pub Details: Synchro-Sette v2 n1 (Volume 2, Issue 1)
Date: January 1983
Pages: 14
Frog sitting on lily pads
Frog sitting on lily pads

Ever wonder how a sort routine works? Is it hard for you to visualize the swapping of variables?

Here is a program that not only allows you to see the variables change places but also generates the individual variables from the DATA variable in line 110. This simulates the READ, DATA and RESTORE commands found on other BASICs.

To speed up the string variable generation, you might want to add the lines:

10 FAST
165 SLOW

To slow down the swapping, add the following lines:

2005 FOR C=1 TO 50
2006 NEXT C
2015 FOR C=1 TO 50
2016 NEXT C

Try to locate both of the words that are being swapped as they change places on the screen. Line 310 checks to see if one of the variables is larger than the other. It does this by examining the numeric value of the codes of each of the characters in the variable.

If the first variable is larger than the second, then lines 330, 340 and 350 swap them around.

100 DIM A$(20,11)
110 LET B$="WATERMELON,BAD JOKE,TARANTULA,KNEE-HIGH,FOOTBALL,SHOE,STINKER,CISTERN,POKER,KITE,SLOP,EYEBALL,LOCKJAW,FLUORESCENT,ZEBRA,BUFFALO,INTEGER,NORMANDY,AUTOMOBILE,JUJITSU,"
120 LET M=1
130 LET I=1
140 FOR N=1 TO LEN B$
150 IF B$(N)="," THEN GOSUB 1000
160 NEXT N
170 FOR I=1 TO 19 STEP 2
180 LET J=J+1
190 GGOSUB 2000
200 NEXT I
210 LET P=0
220 LET M=20
230 LET M=INT M/2
240 IF M=0 THEN GOTO 500
250 LET P=P+1
260 PRINT AT 10,20;"PASS NO. ";P
270 FOR T=1 TO M
280 LET I=T
290 LET J=T+M
300 LET W=0
310 IF A$(I)<A$(J) THEN GOTO 370
320 LET W=1
330 LET C$=A$(I)
340 LET A$(I)=A$(J)
350 LET A$(J)=C$
360 GOSUB 2000
370 LET I=J
380 LET J=J+M
390 IF J<21 THEN GOTO 310
400 IF W=0 THEN GOTO 420
410 GOTO 280
420 NEXT T
430 GOTO 230
500 PRINT AT 21,10;"SORT DONE :::"
510 GOTO 510
1000 LET A$(I)=B$(M TO N-1)
1010 LET M=N+1
1030 LET I=I+1
1040 RETURN
2000 LET D$=" "
2010 PRINT AT I,0;A$(I);D$
2020 PRINT AT J,0;A$(J);D$
2030 RETURN

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