BCX Console Demonstration Program S111.bas

 CONST Maxx = 1000001
 
 GLOBAL A[Maxx] AS INTEGER
 
 GLOBAL B AS INTEGER
 GLOBAL I AS INTEGER
 GLOBAL J AS INTEGER
 GLOBAL L AS INTEGER
 GLOBAL M AS INTEGER
 GLOBAL N AS INTEGER
 
 CLS
 COLOR 2,0
 
 PRINT "***********************************************************************"
 PRINT "            A Shell-Metzner Integer Sort Example For BCX"
 PRINT "             Derived from a program by Judson McClendon"
 PRINT "               based on original work by Donald Knuth"
 PRINT "***********************************************************************"
 PRINT "Sorting 1 million Integers takes about 15 seconds on my 300 mhz Pentium"
 PRINT "***********************************************************************"
 
 PRINT
 
 N = 1000000
 
 PRINT TIME$, ": Storing 1 million random integers"
 
 FOR I = 1 TO N
   A[I] = RND * Maxx    ' Store random integers
 NEXT
 
 COLOR 4,0
 
 PRINT TIME$, ": Starting The Sort"
 CALL Sort
 PRINT TIME$, ": Sorting Complete!"
 
 SUB Sort
   M = 3280
   WHILE M
     FOR J = 1 TO N - M
       L = J + M
       B = A[L]
       FOR I = J TO 1 STEP -M
         IF A[I] > B THEN
           A[I + M] = A[I]
           L = I
         ELSE
           I = 1
         END IF
       NEXT
       A[L] = B
     NEXT
     M = (M - 1) / 3
   WEND
 END SUB