8-Bit Software Online Conversion
Sort - Listing
10ONERRORPROCerror
20REM********
30MODE7
40CLEAR
50PROCinit
60ONERRORPROCerror
70REPEAT
80MODE7
90PROCtitle
100RESTORE460
110FORZ%=1TO5
120READZ$
130PRINTTAB(5,Z%+7);Z%"."Z$
140NEXT
150REPEAT
160PROCcol(5,Z%+8,"Enter menu option:"
)
170H%=(GET-48)
180IFH%=5THENCLS:END
190UNTILH%>0ANDH%<Z%
200PRINTTAB(23,Z%+8)H%
210CLS
220REPEAT
230PROCcol(5,1,"Number of items (2-100
0): ")
240INPUT""N%
250UNTILN%>1ANDN%<1001
260Z%=RND(-799)
270FORZ%=1TON%
280D%(Z%)=INT(100*RND(1)+100)
290NEXT
300PROCprint("Unsorted")
310PRINT''"List being sorted:"
320TIME=0
330IFH%=1THENPROCbubble
340IFH%=2THENPROCbubblef
350IFH%=3THENPROCinsertion
360IFH%=4THENPROCshell
370T=TIME
380PROCprint("Sorted")
390@%=&20209
400PRINT''"Time taken ";T/100;" second
s"
410@%=&00008
420PRINT''
430PROCspace
440UNTILH%=5
450END
460DATABubble,Bubble flagged,Insertion
,Shell,Quit
470:
480DEFPROCinit
490REM*FX229,1
500*TV255
510DIMD%(1000),C%(1000,1)
520N%=0:T%=0:U%=0:V%=0:W%=0:X%=0:Y%=0:
Z%=0
530@%=&00008
540ENDPROC
550:
560DEFPROCcol(X%,Y%,C$)
570PRINTTAB(0,Y%)SPC(40)
580PRINTTAB(0,Y%)CHR$130CHR$157CHR$133
TAB(X%,Y%)C$;
590ENDPROC
600:
610DEFPROCtitle
620PRINTTAB(0,0)CHR$146" <"STRING$(34,
",")"4":FORZ%=1TO2:PRINTCHR$146CHR$141TA
B(2,Z%)"5"CHR$133TAB(7,Z%)" Public Domai
n Software"TAB(36,Z%)CHR$146"5":NEXT
630PRINTTAB(0,3)CHR$146" 5"CHR$133TAB(
10,3)"Sorting Algorithms"TAB(36,3)CHR$14
6"5":PRINTTAB(0,4)CHR$146" 5"TAB(37)"5":
PRINTTAB(0,5)CHR$146" 5"CHR$133TAB(8)"Co
pywrite James Dallas"TAB(36)CHR$146"5"
640PRINTTAB(0,6)CHR$146" -"STRING$(34,
",")"%"
650ENDPROC
660:
670DEFPROCbubble
680FORU%=1TON%-1
690FORV%=1TON%-U%
700IFD%(V%)<=D%(V%+1)THENGOTO740
710T%=D%(V%)
720D%(V%)=D%(V%+1)
730D%(V%+1)=T%
740NEXT
750NEXT
760ENDPROC
770:
780DEFPROCbubblef
790FORU%=1TON%-1
800F%=0
810FORV%=1TON%-U%
820IFD%(V%)<=D%(V%+1)THEN870
830F%=1
840T%=D%(V%)
850D%(V%)=D%(V%+1)
860D%(V%+1)=T%
870NEXT
880IFF%=0THENENDPROC
890NEXT
900ENDPROC
910:
920DEFPROCinsertion
930FORU%=1TON%-1
940V%=U%
950T%=D%(U%+1)
960IFT%>=D%(V%)THEN1000
970D%(V%+1)=D%(V%)
980V%=V%-1
990IFV%>=1THEN960
1000D%(V%+1)=T%
1010NEXT
1020T=TIME
1030ENDPROC
1040:
1050DEFPROCshell
1060Z%=N%
1070REPEAT
1080Z%=INT(Z%/2)
1090FORU%=1TOZ%
1100FORV%=U%TON%-Z%STEPU%
1110W%=V%
1120T%=D%(V%+Z%)
1130IFT%>=D%(W%)THEN1170
1140D%(W%+Z%)=D%(W%)
1150W%=W%-Z%
1160IFW%>=1THEN1130
1170D%(W%+Z%)=T%
1180NEXT
1190NEXT
1200UNTILZ%<1
1210ENDPROC
1220:
1230DEFPROCprint(T$)
1240PRINT''T$" list:"'
1250FORZ%=1TON%
1260PRINTD%(Z%);
1270NEXTZ%
1280ENDPROC
1290:
1300DEFPROCspace
1310VDU23,1,0;0;0;0;
1320PROCcol(5,22,"Press <SPACE BAR> to
continue")
1330REPEATUNTILINKEY(-99)
1340*FX21,0
1350VDU23,1,1;0;0;0;
1360ENDPROC
1370:
1380DEFPROCerror
1390Z$="":Y$=""
1400X$="User error: "
1410IFERR=&9 THENZ$="You have only put
in one "+""""
1420 IFERR=&B THENZ$="Sorry there is no
t enough room to run the program on this
computer. Please return to your supplie
rs who will reimbourse you":END
1430IFERR=&11 THENZ$="You have pressed
the ESCAPE button."
1440IFERR=&13 THENZ$="The maximum lengt
h of an entry is 255 characters"
1450IFERR=&19 THENZ$="There is not enou
gh room to enter the eighty column mode.
Please delete some of your entries"
1460PROCe1(X$,Z$,Y$)
1470ENDPROC
1480DEFPROCe1(X$,Z$,Y$)
1490CLS
1500PROCcol(5,0,"Error")
1510IFLEN(Z$)<2THENX$="Unexpected error
: "
1520PRINT''X$'
1530IFLEN(Z$)<2THENREPORT:PRINT" at lin
e ";ERL
1540IFLEN(Z$)>2THENPROCwrap(Z$):PROCwra
p(Y$)
1550PROCspace
1560ENDPROC
1570:
1580DEFPROCwrap(Z$)
1590S%=1:R%=40:REPEAT
1600B$=MID$(Z$,S%,40):Z%=0:REPEAT
1610Z%=Z%+1:C$=MID$(B$,Z%,1)
1620UNTILASC(C$)=-1ORZ%=40
1630IF ASC(C$)=-1 OR ASC(C$)=32 PRINT B
$:R%=40 ELSE PROCw1
1640S%=S%+R%:UNTIL ASC(C$)=-1:ENDPROC
1650DEFPROCw1
1660W%=0:REPEAT:W%=W%+1
1670W$=RIGHT$(B$,W%):UNTILASC(W$)=32
1680R%=41-W%:B$=MID$(Z$,S%,R%)
1690PRINT B$:ENDPROC