10 CLS :LOCATE 2,30 :PRINT "SHELL SORT"
100 REM SHELL SORT
120 REM SORT A MIXED BATCH OF NUMBERS, B(), INTO ASCENDING ORDER.
130 REM REFERENCE: DL SHELL, `A HIGH-SPEED SORTING PROCEDURE'
140 REM B()  THE BATCH OF NUMBERS
150 REM E$   EXCHANGE  MARKER
160 REM G    THE GAP
170 REM I    INDEX VARIABLE
180 REM S    THE STEP ACROSS THE GAP
190 REM T    THE TOP OF THE PASS THROUGH THE NUMBERS
200 LET N9 = 100   'NUMBER OF DATA
210 DIM B(100)
220 R=VAL(RIGHT$(TIME$,2)) : RANDOMIZE R :
230 PRINT :PRINT "Generating an array of";N9;"random numbers to be sorted :  RANDOMIZE(";R;")":PRINT
380 FOR I = 1 TO N9
390 LET B(I) = INT(RND*25 + 1)
400 NEXT I
410 GOSUB 690
420 PRINT
430 PRINT :PRINT :PRINT "Sorting the numbers now :":PRINT
431 DEF FNT(D)=VAL(MID$(TIME$,1,2))*3600+VAL(MID$(TIME$,4,2))*60+VAL(MID$(TIME$,7,2))
432 TM1=FNT(D) ' ************* Start Timer ***********
450 LET E$ = "  "
460 LET S = 0
470 LET T = 0
480 LET X = 0
490 LET G = N9
510 IF G <=1 THEN 680 ' Test for Finish
520 LET G = INT(G/2)
530 LET T = N9 - G
540 LET E$ = "NO EXCHANGE"
550 FOR I = 1 TO T
560 LET S = I + G
570 IF B(I) <=B(S) THEN 630
580 LET X = B(I)
590 LET B (I) = B (S)
600 LET B(S) = X
610 LET E$ = "EXCHANGE"
630 NEXT I
640 IF E$ = "NO EXCHANGE" THEN 670
650 GOTO 540
670 GOTO 510
680 TM2=FNT(D) : GOTO 750 ' ****** Stop Timer ********
690 FOR I = 1 TO N9 ' ********* Print Array Subroutine ********
700 PRINT B(I);
710 NEXT I
740 RETURN
750 GOSUB 690 : :PRINT :PRINT : PRINT :PRINT "Time to sort";N9;"items :";TM2-TM1;"seconds" :LOCATE 23 :END