Google
 

Trailing-Edge - PDP-10 Archives - decus_20tap4_198111 - decus/20-0103/sorter.bas
There are 2 other files named sorter.bas in the archive. Click here to see a list.
00010 REM SORTER NADDOR
00015 T$="23-MAR-75"
00020 PRINT T$" VERSION"
00025 T0=.5
00030 M9=5
00035 MAT READ M$(M9)
00040 DATA SELECTION,INSERTION,EXCHANGE,QUICKSORT,SHELLSORT
00045 N9=100
00050 DIM A(101),V(101),W(101),B(5),E(5)
00055 C$="RAWDISSEASORSTO"
00090 GOTO 100
00095 PRINT "BAD COMMAND"
00100 PRINT
00105 T2=INT(T0+TIM+.5)
00110 PRINT T2-T1"/"T2"COMMAND";
00115 T1=T2
00120 MAT INPUT C$
00125 PRINT
00130 C=INSTR(C$,LEFT$(C$(1),3))
00135 IF C=0 THEN 95
00140 ON 1+(C-1)/3 GOTO 200,300,400,500,9999
00200 IF NUM<>2 THEN 95
00205 N=VAL(C$(2))
00210 IF N>N9 THEN 95
00215 MAT A=ZER(N)
00220 IF INSTR(C$(1),"/")>0 THEN 245
00225 FOR I=1 TO N
00230 A(I)=INT(N9*RND)
00235 NEXT I
00240 GOTO 265
00245 PRINT N;"NUMBERS";
00250 MAT INPUT A
00255 IF NUM<>N THEN 245
00260 PRINT
00265 MAT W=ZER(N+1)
00270 FOR I=1 TO N
00275 W(I)=A(I)
00280 NEXT I
00285 PRINT "RAW READY"
00290 GOTO 100
00300 IF NUM<>4 THEN 95
00305 MAT A=W
00310 IF C$(2)="RAW" THEN 325
00315 IF LEFT$(C$(2),3)<>"SOR" THEN 95
00320 MAT A=V
00325 R1=VAL(C$(3))
00330 R2=VAL(C$(4))
00335 FOR R=R1 TO R2
00340 PRINT R;TAB(4);A(R)
00345 NEXT R
00350 GOTO 100
00400 IF NUM<>3 THEN 95
00405 V1=VAL(C$(2))
00410 V2=VAL(C$(3))
00415 V(0)=-1E38
00420 V(N+1)=1E38
00425 R1=0
00430 R2=N+1
00435 R=INT((R1+R2)/2)
00440 IF V(R)>=V1 THEN 455
00445 R1=R
00450 GOTO 460
00455 R2=R
00460 IF R2-R1>1 THEN 435
00465 FOR R=R1+1 TO N
00470 IF V(R)>V2 THEN 485
00475 PRINT R;TAB(4);V(R)
00480 NEXT R
00485 GOTO 100
00500 P=SGN(INSTR(C$(1),"/"))
00502 X=10
00504 Y=121
00506 IF LEFT$(C$(2),3)="ALL" THEN 600
00510 M8=NUM-1
00515 FOR M0=1 TO M8
00520 FOR M=1 TO M9
00525 IF LEFT$(M$(M),3)=LEFT$(C$(M0+1),3) THEN 540
00530 NEXT M
00535 GOTO 95
00540 M(M0)=M
00545 IF (M-4)*(M-5)<>0 THEN 585
00550 K=INSTR(C$(M0+1),"/")
00555 IF K=0 THEN 585
00560 J=VAL(MID$(C$(M0+1),K+1))
00565 IF M=5 THEN 580
00570 X=J
00575 GOTO 585
00580 Y=J
00585 NEXT M0
00590 GOTO 700
00600 M8=M9
00605 FOR M0=1 TO M8
00610 M(M0)=M0
00615 NEXT M0
00620 K=INSTR(C$(2),"/")
00625 IF K=0 THEN 700
00630 X=VAL(MID$(C$(2),K+1))
00700 FOR M0=1 TO M8
00705 M=M(M0)
00710 PRINT M$(M);
00715 MAT V=W
00720 IF P=0 THEN 735
00725 PRINT 
00730 GOSUB 9000
00735 C=TIM
00740 GOSUB 995
00745 T$=STR$(INT(100*(TIM-C)+.5))
00750 PRINT TAB(14-LEN(T$));T$" CSEC"
00755 NEXT M0
00760 GOTO 100
00995 ON M GOTO 1000,2000,3000,4000,5000
01000 FOR I=1 TO N-1
01005 L=V(I)
01010 K=I
01015 FOR J=I+1 TO N
01020 IF V(J)>=L THEN 1035
01025 L=V(J)
01030 K=J
01035 NEXT J
01040 IF K<=I THEN 1055
01045 V(K)=V(I)
01050 V(I)=L
01055 GOSUB 9000
01060 NEXT I
01065 RETURN
02000 FOR I=2 TO N
02005 T=V(I)
02010 FOR J=I-1 TO 1 STEP -1
02015 IF V(J)<=T THEN 2035
02020 V(J+1)=V(J)
02025 NEXT J
02030 J=0
02035 V(J+1)=T
02040 GOSUB 9000
02045 NEXT I
02050 RETURN
03000 Z=N
03005 T=0
03010 FOR I=2 TO Z
03015 IF V(I-1)<=V(I) THEN 3040
03020 T=I
03025 L=V(I)
03030 V(I)=V(I-1)
03035 V(I-1)=L
03040 NEXT I
03045 GOSUB 9000
03050 Z=T-1
03055 IF Z>1 THEN 3005
03060 RETURN
04000 L=1
04005 H=N
04010 S=0
04015 V(N+1)=1E38
04100 IF H-L<X THEN 4600
04105 I=L
04110 J=H+1
04115 V=V(I)
04200 J=J-1
04205 IF V<V(J) THEN 4200
04210 IF J<=I THEN 4500
04215 V(I)=V(J)
04300 I=I+1
04305 IF V(I)<V THEN 4300
04310 IF I>=J THEN 4400
04315 V(J)=V(I)
04320 GOTO 4200
04400 I=J
04500 V(I)=V
04505 S=S+1
04510 GOSUB 9000
04515 IF H-I<=I-L THEN 4540
04520 B(S)=I+1
04525 E(S)=H
04530 H=I-1
04535 GO TO 4100
04540 B(S)=L
04545 E(S)=I-1
04550 L=I+1
04555 GO TO 4100
04600 FOR I=L+1 TO H
04605 T=V(I)
04610 FOR J=I-1 TO L STEP -1
04615 IF V(J)<=T THEN 4635
04620 V(J+1)=V(J)
04625 NEXT J
04630 J=L-1
04635 V(J+1)=T
04640 NEXT I
04645 GOSUB 9000
04700 IF S<=0 THEN 4800
04705 L=B(S)
04710 H=E(S)
04715 S=S-1
04720 GO TO 4100
04800 RETURN
05000 FOR I=Y+1 TO N
05005 T=V(I)
05010 FOR J=I-Y TO 1 STEP -Y
05015 IF V(J)<=T THEN 5035
05020 V(J+Y)=V(J)
05025 NEXT J
05030 J=J-Y
05035 V(J+Y)=T
05040 NEXT I
05045 IF Y>=N THEN 5055
05050 GOSUB 9000
05055 Y=INT(Y/3)
05060 IF Y>=1 THEN 5000
05065 RETURN
09000 IF P=0 THEN 9025
09005 FOR Q=1 TO N
09010 PRINT V(Q);
09015 NEXT Q
09020 PRINT
09025 RETURN
09999 END