8-Bit Software Online Conversion
:0.$.BUBCOMP - Listing
10MODE7:@%=&00000405:max%=1000
20PRINT'" How many numbers are to be
sorted"'" between 2 and 10 ":REPEAT:INPU
T nos%:UNTIL (nos%>1) AND (nos%<11)
30PRINT" Array size 2^";nos%;" = ";2^
nos%
40DIM times%(4,nos%,4),A%(2^nos%)
50FOR loop%= 1 TO 4:FOR loopy%= 1 TO
nos%: times%(loop%,loopy%,1)=99999999 :N
EXT loopy%:NEXT loop%
60PRINT'" How many different groups o
f data"'" are to be sorted between"'" 1
and 10":REPEAT:INPUTcompare%:UNTIL (comp
are%>0) AND (compare%<11)
70MODE0:VDU23;8202;0;0;0;:PRINTTAB(0,
1);" Current sort type :"
80PRINTTAB(0,2);" Current sort size :
"
90PRINTTAB(15,4);"Array size"
100PRINTTAB(0,6);"Sort type"
110FOR loop%=1 TO 4:PRINTTAB(8,loop%*4
+4);"min":PRINTTAB(8,loop%*4+5);"av.":PR
INTTAB(8,loop%*4+6);"max":NEXT loop%
120PRINTTAB(0,9);"Shrink":PRINTTAB(0,1
3);"Twobub":PRINTTAB(0,17);"Twobubs":PRI
NTTAB(0,21);"Comb"
130FOR seed%=1 TO compare%
140FOR loopy%=2 TO nos%
150PRINTTAB(loopy%*7,6);2^loopy%
160size%=2^loopy%
170PRINTTAB(21,2);" ":PRINTTAB(21,2
);size%
180sort%=1:PRINTTAB(21,1);"Shrink ":
PROCshrink`sort
190sort%=2:PRINTTAB(21,1);"Twobub ":
PROCtwobub`sort
200sort%=3:PRINTTAB(21,1);"Twobubs ":
PROCtwobubs`sort
210sort%=4:PRINTTAB(21,1);"Combsort ":
PROCcomb`sort
220NEXT loopy%:NEXT seed%
230PRINTCHR$(0,20);"Finished."
240END
250:
260DEFPROCrandomize
270s=RND(-seed%)
280FOR loop%=0 TO size%
290A%(loop%)=RND(max%)
300NEXT loop%
310time%=TIME
320ENDPROC
330:
340DEFPROCtiming
350time%=TIME-time%
360IF time% < times%(sort%,loopy%,1) T
HEN times%(sort%,loopy%,1) = time%
370PRINTTAB(loopy%*7,sort%*4+4);times%
(sort%,loopy%,1)/100
380IF time% > times%(sort%,loopy%,3) T
HEN times%(sort%,loopy%,3) = time%
390PRINTTAB(loopy%*7,sort%*4+6);times%
(sort%,loopy%,3)/100
400IF 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
410PRINTTAB(loopy%*7,sort%*4+5);times%
(sort%,loopy%,2)/100
420ENDPROC
430:
440DEFPROCshrink`sort
450PROCrandomize
460low%=size%
470REPEAT
480flag=FALSE
490FOR loop%=0 TO low%-1
500IF A%(loop%)<A%(loop%+1) THEN swap%
=A%(loop%):A%(loop%)=A%(loop%+1):A%(loop
%+1)=swap%:flag=TRUE
510NEXT loop%
520low%=low%-1
530UNTIL flag=FALSE
540PROCtiming
550ENDPROC
560:
570DEFPROCtwobub`sort
580PROCrandomize
590REPEAT
600flag=FALSE
610FOR loop%=0 TO size%-1
620IF A%(loop%)<A%(loop%+1) THEN swap%
=A%(loop%):A%(loop%)=A%(loop%+1):A%(loop
%+1)=swap%:flag=TRUE
630NEXT loop%
640FOR loop%=size% TO 1 STEP -1
650IF A%(loop%)>A%(loop%-1) THEN swap%
=A%(loop%):A%(loop%)=A%(loop%-1):A%(loop
%-1)=swap%:flag=TRUE
660NEXT loop%
670UNTIL flag=FALSE
680PROCtiming
690ENDPROC
700:
710DEFPROCtwobubs`sort
720PROCrandomize
730low%=0:high%=size%
740REPEAT
750flag=FALSE
760FOR loop%=low% TO high%-1
770IF A%(loop%)<A%(loop%+1) THEN swap%
=A%(loop%):A%(loop%)=A%(loop%+1):A%(loop
%+1)=swap%:flag=TRUE
780NEXT loop%
790high%=high%-1
800FOR loop%=high% TO low%+1 STEP -1
810IF A%(loop%)>A%(loop%-1) THEN swap%
=A%(loop%):A%(loop%)=A%(loop%-1):A%(loop
%-1)=swap%:flag=TRUE
820NEXT loop%
830low%=low%+1
840UNTIL flag=FALSE
850PROCtiming
860ENDPROC
870:
880DEFPROCcomb`sort
890PROCrandomize
900gap%=size%
910REPEAT
920flag=FALSE
930gap%=gap%/1.3
940IF gap%<1 gap%=1
950IF (gap%=9)OR(gap%=10) gap%=11
960FOR pos%=0 TO size%-gap%
970IF A%(pos%)<A%(pos%+gap%) THEN swap
%=A%(pos%):A%(pos%)=A%(pos%+gap%):A%(pos
%+gap%)=swap%:flag=TRUE
980NEXT pos%
990UNTIL (flag=FALSE)AND(gap%=1)
1000PROCtiming
1010ENDPROC