0REM * PUBLIC DOMAIN SOFTWARE *
5 CLEAR 5000
100 CLS '****** SORT PROGRAM *******
110 DIM N(150),C$(150)
130 PRINT"TYPE  C  FOR CHARACTER STRING SORT"
140 PRINT"TYPE  N  FOR NUMBER SORT"
150 INPUT W$
160 N=0:PRINT:PRINT
170 IF W$="N" GOTO 480
180 IF W$<>"C" THEN 130
190 GOSUB 720
200 INPUT S$
210 N=N+1
220 INPUT C$(N)
230 IF C$(N)<>S$ THEN 210
240 N=N-1:PRINT
250 L=INT(N/2)+1
260 N1=N
270 IF L=1 THEN 310
280 L=L-1
290 A$=C$(L)
300 GOTO 350
310 A$=C$(N1)
320 C$(N1)=C$(1)
330 N1=N1-1
340 IF N1=1 THEN 440
350 J=L
360 I=J
370 J=2*J
380 IF J=N1 THEN 400
390 IF J>N1 THEN 420
392 IF C$(J)>=C$(J+1) THEN 400
396 J=J+1
400 IF A$>=C$(J) THEN 420
410 C$(I)=C$(J)
415 GOTO 360
420 C$(I)=A$
425 GOTO 270
440 C$(1)=A$
450 FOR I=1 TO N
453 LPRINT C$(I)
456 NEXT I
460 GOTO 130
480 GOSUB 720
483 INPUT S
486 PRINT
490 N=N+1
493 INPUT N(N)
496 IF N(N)<>S THEN 490
500 N=N-1
505 PRINT
520 L=INT(N/2)+1
525 N1=N
530 IF L=1 THEN 550
540 L=L-1
543 A=N(L)
546 GOTO 590
550 A=N(N1)
555 N(N1)=N(1)
560 N1=N1-1
570 IF N1=1 THEN 680
590 J=L
600 I=J
605 J=2*J
610 IF J=N1 THEN 640
620 IF J>N1 THEN 660
630 IF N(J)N(J) THEN 660
650 N(I)=N(J)
655 GOTO 600
660 N(I)=A
665 GOTO 530
680 N(1)=A
690 FOR I=1 TO N
693 LPRINT N(I)
696 NEXT I
700 GOTO 130
720 PRINT"INDICATE A STOP CODE TO INDICATE END OF LIST"
740 RETURN