Sort Demo

Related Articles: An Assortment of Sorts
Developer(s): William Tracy, D. J. Currie
Date: 1983
Type: Program
Platform(s): TS 2068

From SYNC Nov 1983 issue. Demonstrates several kinds of sort.

Appears on

Library tape of the Indiana Sinclair Timex User’s Group.

Gallery

Source Code

 8000 BORDER 0: PAPER 0: CLS : INK 7
 8010 REM   NO. SORT  
 8030 INPUT "HOW MANY NUMBERS TO SORT?  "; NUM
 8050 DIM U(NUM)
 8060 CLS 
 8070 GO SUB 9060
 8080 LET A=NUM
 8090 GO SUB 9100
 8100 INPUT "Which sorting method ?  ";W$
 8110 PRINT FLASH 1;AT 19,20;" COMPUTING "
 8120 IF W$="1" THEN GO TO 8180
 8130 IF W$="2" THEN GO TO 8310
 8140 IF W$="3" THEN GO TO 8470
 8150 IF W$="4" THEN GO TO 8670
 8160 CLS 
 8170 GO TO 8090
 8180 REM  BUBBLE SORT -VERY GOOD
 8190 FOR Q=1 TO NUM-1
 8200 FOR R=1 TO NUM-Q
 8210 LET H=U(R)
 8220 LET I=U(R+1)
 8230 IF H<=I THEN GO TO 8260
 8240 LET U(R)=I
 8250 LET U(R+1)=H
 8260 NEXT R
 8270 NEXT Q
 8280 GO TO 8950
 8290 REM  END OF BUBBLE SORT 
 8300 REM 
 8310 REM   FLOAT SORT  
 8320 LET Q=U(1)
 8330 LET K=1
 8340 FOR S=2 TO NUM
 8350 IF U(S)<Q THEN GO TO 8380
 8360 LET Q=U(S)
 8370 LET K=S
 8380 NEXT S
 8390 LET Z=U(NUM)
 8400 LET U(NUM)=U(K)
 8410 LET U(K)=Z
 8420 LET NUM=NUM-1
 8430 IF NUM>1 THEN GO TO 8320
 8440 GO TO 8950
 8450 REM  END OF FLOAT SORT 
 8460 REM 
 8470 REM  SHELL SORT - BEST  
 8480 LET S=1
 8490 LET S=S*2
 8500 IF S<=NUM THEN GO TO 8490
 8510 LET S=INT (S/2)
 8520 IF S=0 THEN GO TO 8950
 8530 FOR T=1 TO NUM-S
 8540 LET Y=T
 8550 LET W=Y+S
 8560 IF U(Y)<=U(W) THEN GO TO 8620
 8570 LET Z=U(Y)
 8580 LET U(Y)=U(W)
 8590 LET U(W)=Z
 8600 LET Y=Y-S
 8610 IF Y>0 THEN GO TO 8550
 8620 NEXT T
 8630 GO TO 8510
 8640 REM  END OF SHELL SORT 
 8650 REM 
 8670 REM  QUICK SORT -FASTEST 
 8680 DIM S(NUM,2)
 8690 LET P=0
 8700 LET L=1
 8710 LET R=NUM
 8720 LET I=L
 8730 LET J=R
 8740 LET S=-1
 8750 IF U(I)<=U(J) THEN GO TO 8800
 8760 LET T=U(I)
 8770 LET U(I)=U(J)
 8780 LET U(J)=T
 8790 LET S=-S
 8800 IF S=1 THEN LET I=I+1
 8810 IF S=-1 THEN LET J=J-1
 8820 IF I<J THEN GO TO 8750
 8830 IF I+1>=R THEN GO TO 8870
 8840 LET P=P+1
 8850 LET S(P,1)=I+1
 8860 LET S(P,2)=R
 8870 LET R=I-1
 8880 IF L<R THEN GO TO 8720
 8890 IF P=0 THEN GO TO 8950
 8900 LET L=S(P,1)
 8910 LET R=S(P,2)
 8920 LET P=P-1
 8930 GO TO 8720
 8940 REM  END OF QUICK SORT 
 8950 CLS 
 8960 PRINT "ARRAY SORTED:"
 8980 FOR X=1 TO A
 8990 PRINT U(X)
 9010 NEXT X
 9020 INPUT "ANOTHER RUN (Y/N)?  ";V$: IF V$<>"Y" AND V$<>"y" THEN STOP 
 9030 CLS 
 9040 GO TO 8000
 9050 REM *** GENERATES RANDOM   NUMBERS AND FILLS ARRAY ***
 9060 CLS 
 9063 PRINT "RANDOM NUMBERS:"
 9068 FOR X=1 TO NUM
 9070 LET U(X)=INT (RND*99)
 9075 PRINT u(x)
 9080 NEXT X
 9090 RETURN 
 9100 PRINT AT 4,8;"SORTING METHODS";AT 5,8;"--------------";AT 7,8;"1. BUBBLE SORT";AT 9,8;"2. FLOAT SORT";AT 11,8;"3. SHELL SORT";AT 13,8;"4. QUICK SORT"
 9110 RETURN 
 9120 REM  FROM SYNC MAGAZINE NOV? 1983     ADAPTED BY D.J.CURRIE
 9998 SAVE "# SORT" LINE 8000
Scroll to Top