3 REM SORTKYBD.BAS   MBASIC 5.2  CP/M ver  4/12/81
5 REM SORT LISTS KEYED IN TO PROGRAM & DISPLAY ON CRT.
6 E$=CHR$(27):CLR$=E$+"E":PRINT CLR$:PRINT:PRINT
7 PRINT "          ";E$;"p";"  SORT PROGRAM FOR LISTS KEYED IN.  ";E$;"q"
9 PRINT:PRINT
10 REM ******CHARACTER STRING / NUMBER SORT******
20 REM	 ******FROM CP/M USERS GROUP 5.22******
30 REM	    EDITED BY KEITH PETERSEN, W8SDZ
40 CLEAR 500
50 DIM N(150),C$(150)
60 PRINT:PRINT "TYPE C FOR CHARACTER (alphabetic) STRING SORT, .... or"
65 PRINT
70 PRINT "TYPE N FOR NUMBER SORT.   (Numeric items only). ";
80 INPUT W$
90 N=0
100 PRINT
110 IF W$="N" THEN 480
112 IF W$="n" THEN 480
115 IF W$="C" THEN 140
117 IF W$="c" THEN 140
120 GOTO 60
130 REM **********CHARACTER STRING SORT ROUTINE***********
140 GOSUB 770
150 INPUT S$
160 PRINT
163 PRINT "BEGIN ENTERING ALPHABETIC ITEMS.   ENTER ";S$;
164 PRINT "TO END YOUR LIST AND BEGIN THE SORTING.":PRINT
170 N=N+1
180 INPUT C$(N)
190 IF C$(N)<>S$ THEN 170
200 N=N-1
210 PRINT
220 L=INT(N/2)+1
230 N1=N
240 IF L=1 THEN 280
250 L=L-1
260 A$=C$(L)
270 GOTO 320
280 A$=C$(N1)
290 C$(N1)=C$(1)
300 N1=N1-1
310 IF N1=1 THEN 430
320 J=L
330 I=J
340 J=2*J
350 IF J=N1 THEN 390
360 IF J>N1 THEN 420
370 IF C$(J)>=C$(J+1) THEN 390
380 J=J+1
390 IF A$>=C$(J) THEN 420
400 C$(I)=C$(J)
410 GOTO 330
420 C$(I)=A$:GOTO 240
430 C$(1)=A$
440 FOR I=1 TO N
450 PRINT C$(I):NEXT I
460 PRINT CLR$:GOTO 60
470 REM *************NUMBER SORTING ROUTINE*************
480 GOSUB 770 
483 PRINT:PRINT:PRINT "...item must be numeric, it can be +, -, or period."
490 INPUT S:PRINT
500 N=N+1
510 INPUT N(N)
520 IF N(N)<>S THEN 500
530 N=N-1
540 PRINT
550 L=INT(N/2)+1
560 N1=N
570 IF L=1 THEN 600
580 L=L-1
590 A=N(L):GOTO 630
600 A=N(N1):N(N1)=N(1)
610 N1=N1-1
620 IF N1=1 THEN 730
630 J=L
640 I=J
650 J=2*J
660 IF J=N1 THEN 690
670 IF J>N1 THEN 720
680 IF N(J)<N(J+1) THEN J=J+1
690 IF A>N(J) THEN 720
700 N(I)=N(J)
710 GOTO 640
720 N(I)=A:GOTO 570
730 N(1)=A
740 FOR I=1 TO N:PRINT N(I):NEXT
750 PRINT CLR$:GOTO 60
760 REM **********SUBROUTINE TO INPUT STOP CODE**********
770 PRINT:PRINT "Please enter a 'stop-code'; ...an item not it your "
775 PRINT
780 PRINT "list which will indicate you are finished entering.  ";
790 RETURN
800 END
 ...an item not it your "
775 PRINT
780 PRINT "list which will indicate you are finished entering.  ";
790 RETURN
800 END

750 PRINT CLR$:GOTO 60
760 REM **********SUBROUTINE TO INPUT STOP CODE**********
770 PRINT:PRINT "Please enter a 'stop-code'