Cls

10 PRINT'SHELL SORT PROGRAM" 100 DIM A(300)

105 PRINT

106 PRINT'This program can sort up to 300 entries." 108 PRINT

110 PRINT'Enter 99999 as data to terminate data entry," 115 PRINT 120 K=0 125 K = K+1 130 PRINT"A(";K;") = "; 135 INPUT"";TP

140 IF TP = 99999! THEN K = K-1:GOTO 150 145 A(K)=TP:GOTO 125 150 N = K 180 GOSUB 500 190 PRINT:PRINT

195 PRINT" Sorted list":PRINT

230 PRINT A(l)

231 IF K> =20 THEN INPUT'Touch <return>.";W$: K = 0:CLS 240 NEXT I

250 INPUT'Touch < return > to clear screen and terminate run.";W$ 255 CLS.END 500 D = 1 510 D = 2*D

520 IF D< =N THEN 510 530 D = INT((D-1 )/2) 540 IF D = 0 THEN 700 550 FOR 1 = 1 TO N-D 560 J = l 570 L = J + D

580 IF A(J) < =A(L) THEN 640 590 X = A(J) 600 A(J) =A(L) 610 A(L) =X 620 J = J-D

630 IF J >0 THEN 570 640 NEXT I 650 GOTO 530 700 RETURN

10 'bubble sort 15 CLS 20 DIM X(300)

0 0

Post a comment