8-Bit Software Online Conversion

:2.B.COMPARE - Listing

10IF PAGE<>&1200 THEN PAGE=&1200:CHAI N"B.COMPARE" 20REM SORT COMP BY H.S.W. 1991 30MODE7:@%=&00000405 40ONERRORREPORT:PRINT" at line ";ERL: END 50max%=1000 60PRINT'" How many numbers are to be sorted"'" between 2 and 10 ":REPEAT:INPU T nos%:UNTIL (nos%>1) AND (nos%<11) 70PRINT" Array size 2^";nos%;" = ";2^ nos% 80DIM times%(3,nos%,3) 90DIM A%(2^nos%) 100FOR loop%= 1 TO 3:FOR loopy%= 1 TO nos%: times%(loop%,loopy%,1)=99999999 :N EXT loopy%:NEXT loop% 110PRINT'" How many different groups o f data"'" are to be sorted between"'" 1 and 10":REPEAT:INPUTcompare%:UNTIL (comp are%>0) AND (compare%<11) 120MODE0:VDU23;8202;0;0;0;:PRINTTAB(0, 1);" Current sort type :" 130PRINTTAB(0,2);" Current sort size : " 140PRINTTAB(15,4);"Array size" 150PRINTTAB(0,6);"Sort type" 160FOR loop%=1 TO 3:PRINTTAB(7,loop%*4 +4);"min":PRINTTAB(7,loop%*4+5);"av.":PR INTTAB(7,loop%*4+6);"max":NEXT loop% 170PRINTTAB(0,9);"Bubble":PRINTTAB(0,1 3);"Select":PRINTTAB(0,17);"Shell" 180FOR seed%=1 TO compare% 190FOR loopy%=2 TO nos% 200PRINTTAB(loopy%*7,6);2^loopy% 210size%=2^loopy% 220PRINTTAB(21,2);" ":PRINTTAB(21,2 );size% 230sort%=1:PRINTTAB(21,1);"Bubble ": PROCbubble`sort 240sort%=2:PRINTTAB(21,1);"Selection": PROCselection`sort 250sort%=3:PRINTTAB(21,1);"Shell ": PROCshell`sort 260NEXT loopy%:NEXT seed% 270PRINTCHR$(0,20);"Finished." 280END 290: 300DEFPROCrandomize 310s=RND(-seed%) 320FOR loop%=0 TO size% 330A%(loop%)=RND(max%) 340NEXT loop% 350time%=TIME 360ENDPROC 370: 380DEFPROCbubble`sort 390PROCrandomize 400REPEAT 410flag=FALSE 420FOR loop%=0 TO size%-1 430IF A%(loop%)<A%(loop%+1) THEN swap% =A%(loop%):A%(loop%)=A%(loop%+1):A%(loop %+1)=swap%:flag=TRUE 440NEXT loop% 450UNTIL flag=FALSE 460PROCtiming 470ENDPROC 480: 490DEFPROCselection`sort 500PROCrandomize 510counter%=size%:position%=0 520REPEAT 530minsofar%=max% 540FOR loop%=0 TO counter% 550IF A%(loop%)<minsofar% THEN positio n%=loop%:minsofar%=A%(loop%) 560NEXT loop% 570swap%=A%(counter%):A%(counter%)=A%( position%):A%(position%)=swap% 580counter%=counter%-1 590UNTIL (position%=0) 600PROCtiming 610ENDPROC 620: 630DEFPROCshell`sort 640PROCrandomize 650counter%=size% 660REPEAT 670counter%=counter% DIV 2 680FOR loop%=0 TO size%-counter% 690low%=loop% 700high%=counter%+loop% 710REPEAT 720flag=FALSE 730IF A%(high%)>A%(low%) THEN swap%=A% (low%):A%(low%)=A%(high%):A%(high%)=swap %:high%=low%:low%=low%-counter%:flag=TRU E 740UNTIL (flag=FALSE) OR (low%<=0) 750NEXT loop% 760UNTIL counter%<=0 770PROCtiming 780ENDPROC 790: 800DEFPROCtiming 810time%=TIME-time% 820IF time% < times%(sort%,loopy%,1) T HEN times%(sort%,loopy%,1) = time% 830PRINTTAB(loopy%*7,sort%*4+4);times% (sort%,loopy%,1)/100 840IF time% > times%(sort%,loopy%,3) T HEN times%(sort%,loopy%,3) = time% 850PRINTTAB(loopy%*7,sort%*4+6);times% (sort%,loopy%,3)/100 860IF times%(sort%,loopy%,2)=0 THEN ti mes%(sort%,loopy%,2)=time% ELSE times%(s ort%,loopy%,2)=(times%(sort%,loopy%,2)+t ime%)/2 870PRINTTAB(loopy%*7,sort%*4+5);times% (sort%,loopy%,2)/100 880ENDPROC