Classic Computer Magazine Archive PROGRAM LISTING: 89-08/SHELSORT.LST


10 REM SHELL SORT
15 REM BY DOUG WHITE
17 REM (C)1989 ANTIC PUBLISHING INC.
20 DIM A(1000)
30 GRAPHICS 0
40 ? "     SHELL SORT"
50 ? :? "HOW MANY #'S ARE YOU SORTING (< 1000)"
60 INPUT NUM
70 IF NUM>1000 THEN 50
80 ? :? "FILLING THE ARRAY WITH UNSORTED #'S"
90 FOR N=1 TO NUM
100 A(N)=INT(10000*SIN(N))
110 NEXT N
120 ? :? " ***  SORTING  ***"
130 POKE 18,0:POKE 19,0:POKE 20,0
140 REM 
500 REM ..... BEGINNING OF SHELL SORT
510 PSIZE=1
520 PSIZE=PSIZE*3+1
530 IF PSIZE<NUM THEN 520
540 REM 
550 PSIZE=INT(PSIZE/3)
560 ? "PARTITION SIZE = ",PSIZE
570 REM 
580 FOR N=1+PSIZE TO NUM
590 TEMP=A(N)
600 K=N-PSIZE
610 FOR J=K TO 1 STEP -PSIZE
620 IF TEMP<A(J) THEN 650
630 A(J+PSIZE)=A(J)
640 NEXT J
650 A(J+PSIZE)=TEMP
660 NEXT N
670 IF PSIZE>1 THEN 550
680 REM ..... END OF SHELL SORT
1000 REM 
1010 T=PEEK(20)+256*PEEK(19)
1020 SOUND 3,100,10,2
1030 FOR N=1 TO NUM:? N,A(N):NEXT N
1040 ? :? T/60;" SECONDS "
1050 END 

Back to previous page