home *** CD-ROM | disk | FTP | other *** search
/ Loadstar 96 / 096.d81 / sort.bas (.txt) < prev    next >
Commodore BASIC  |  2022-08-26  |  15KB  |  458 lines

  1. 0 ifa=0thena=1:load"[209][215][201][208][197]",8,1
  2. 5 rem@ s 1024
  3. 10 poke45,124:poke46,103:clr:mx=200:dimar(200),sl(10),sr(10),te$(500),s(11),f(8)
  4. 11 dv=peek(186):ifdv<8thendv=8
  5. 12 load"[209][215][201][208][197]",dv,128
  6. 20 deffnhz(x)=int(x/16)
  7. 30 deffnps(x)=4^(3-(xand12)/4)
  8. 40 deffncl(x)=(xand3)
  9. 50 deffnme(z)=57344+int((y-1)/8)*320+x*8+((y-1)and7)
  10. 60 poke53280,0:poke53281,0:poke53270,200
  11. 70 poke56576,4:poke53272,18:poke648,196:poke53265,27
  12. 80 forx=1to9:readmn$(x):next
  13. 90 data"1.[160][201]nsertion[160][211]ort[160][160][160][160][160][160][160][160]","2.[160][211]election[160][211]ort[160][160][160][160][160][160][160][160]"
  14. 100 data"3.[160][196]elayed[160][211]election[160][211]ort","4.[160][194]ubble[160][211]ort[160][160][160][160][160][160][160][160][160][160][160]"
  15. 110 data"5.[160][211]hell[160][211]ort[160][160][160][160][160][160][160][160][160][160][160][160]","6.[160][200]eap[160][211]ort[160][160][160][160][160][160][160][160][160][160][160][160][160]"
  16. 120 data"7.[160][209]uicksort[160][160][160][160][160][160][160][160][160][160][160][160][160]","8.[160][209]uit[160]to[160][204]oad[211]tar[160][160][160][160][160][160]"
  17. 130 data"9.[160][208]laying[160][215]ith[160][211]orts[160][160][160][160]"
  18. 140 forx=1to9:readln(x):next
  19. 145 print"[147]":s%=1:fori=1to284:readte$(i):ifval(te$(i))=-2thens%=s%+1:s(s%)=i+1
  20. 146 next
  21. 150 data 14,14,22,11,10,9,10,,18
  22. 160 gosub1590:print"";:printtab(6)"[159][176][163][163][163][163][163][163][163][163][163][163][163][163][163][163][163][163][163][163][163][163][163][163][163][163][163][174]"
  23. 170 printtab(6)"[165][160][160][160][160][160][160][160][160][156][211]ort[160][196]emo[160][160][160][160][160][160][160][160][159][167] [159]"
  24. 180 printtab(6)"[165][160][160][160][160][160][160][156][194]y[160][194]rian[160][194]oese[160][160][160][160][160][159][167] [159]"
  25. 190 printtab(6)"[165][160][160][160][160][160][160][160][160][160][160][160][160][160][160][160][160][160][160][160][160][160][160][160][160][160][167] [159]"
  26. 200 printtab(6)"[165]"mn$(1)"[159][167] [159]"
  27. 210 forx=2to8:printtab(6)"[165][154]"mn$(x)"[159][167] [159]":next
  28. 220 printtab(6)"[173][164][164][164][164][164][164][164][164][164][164][164][164][164][164][164][164][164][164][164][164][164][164][164][164][164][189] "
  29. 230 printtab(7)"                           ":sr=1
  30. 240 geta$:if(a$<>"[145]")and(a$<>"")and(a$<>chr$(13))and((a$<"1")or(a$>"9"))then240
  31. 250 print"[154]";:forx=1tosr:print"";:next:printtab(7)mn$(sr)
  32. 260 ifa$=""thensr=sr+1:ifsr=9thensr=1
  33. 270 ifa$="[145]"thensr=sr-1:ifsr=0thensr=8
  34. 280 if(a$>"0")and(a$<":")thensr=val(a$):goto310
  35. 290 print"";:forx=1tosr:print"";:next:printtab(7)mn$(sr)
  36. 300 ifa$<>chr$(13)then240
  37. 310 gosub2000:print"[147]":gosub2020:print"[147]":gosub2010:ifsr<>8then360
  38. 320 poke56576,151:poke648,4:poke53272,21:print"[147]"
  39. 330 open15,8,15,"r0:hello connect=hello connect":input#15,er:close15
  40. 340 ifer<>63thenend
  41. 350 f$="hello connect":print"[147]loadf$,8":poke631,19:poke632,131:poke198,2:end
  42. 360 poke53280,2:poke53272,8:poke53265,59:poke53270,216
  43. 370 sys828:poke53280,6
  44. 380 fory=1tomx:ar(y)=int(rnd(0)*160)*4+int(rnd(0)*3)+1
  45. 390 x=fnhz(ar(y)):cl=fncl(ar(y))*fnps(ar(y)):pokefnme(.),cl:next:poke53280,0
  46. 400 ab=0:onsrgosub570,650,740,830,930,1040,1260,400,1470
  47. 410 poke53280,4:poke198,0:wait198,1:geta$:poke53280,0
  48. 420 poke53272,18:poke648,196:poke53265,27:poke53270,200
  49. 430 gosub1590:print""tab(6)"[159][176][163][163][163][163][163][163][163][163][163][163][163][163][163][163][163][163][163][163][163][163][163][163][163][163][163][174]"
  50. 440 printtab(6)"[165][160][160][160][160][160][160][160][160][160][160][160][160][160][160][160][160][160][160][160][160][160][160][160][160][160][167] [145][156]"
  51. 450 forx=1to(40-ln(sr))/2:print"";:next:printmid$(mn$(sr),4,ln(sr))
  52. 460 printtab(6)"[159][165][160][160][160][160][160][160][160][160][160][160][160][160][160][160][160][160][160][160][160][160][160][160][160][160][160][167] "
  53. 470 if(ab)thenprinttab(6)"[159][165][154][160][160][212]he[160]sort[160]was[160]aborted.[160][160][159][167] ":goto500
  54. 480 printtab(6)"[159][165][154][160][160][160][160][160][160]data[160]items[160]sorted[160][160][159][167] [145]"
  55. 490 printtab(9)"[154]"mid$(str$(mx),2)
  56. 500 printtab(6)"[159][165][154][160][160][160][212]ime[160]taken:[160][160][160][160][160][160][160][160][160][160][160][159][167] [145][154]"
  57. 510 printtab(24)mid$(t$,3,2)":"mid$(t$,5,2)
  58. 520 printtab(6)"[159][165][160][160][160][160][160][160][160][160][160][160][160][160][160][160][160][160][160][160][160][160][160][160][160][160][160][167] "
  59. 530 printtab(6)"[159][165][208]ress[160]any[160]key[160]to[160]continue[159][167] "
  60. 540 printtab(6)"[159][173][164][164][164][164][164][164][164][164][164][164][164][164][164][164][164][164][164][164][164][164][164][164][164][164][164][189] "
  61. 550 printtab(7)"                           "
  62. 560 poke198,0:wait198,1:geta$:goto160
  63. 570 ti$="000000":fori=2tomx:j=i-1:vl=ar(i):rem 1st line of insertion sort
  64. 580 gosub1570:if(ab)theni=mx:goto620
  65. 590 if(vl<ar(j))and(j>0)thengosub630:j=j-1:goto580
  66. 600 y=j+1:x=fnhz(ar(y)):pokefnme(.),0
  67. 610 ar(j+1)=vl:x=fnhz(ar(y)):cl=fncl(ar(y))*fnps(ar(y)):pokefnme(.),cl
  68. 620 next:t$=ti$:return
  69. 630 y=j+1:x=fnhz(ar(y)):pokefnme(.),0:ar(j+1)=ar(j)
  70. 640 x=fnhz(ar(y)):cl=fncl(ar(y))*fnps(ar(y)):pokefnme(.),cl:return
  71. 650 ti$="000000":rem 1st line of selection sort
  72. 660 fori=1tomx-1:forj=mxtoi+1step-1:ifar(j)<ar(i)thengosub690
  73. 670 gosub1570:if(ab)thenj=i+1:i=mx-1
  74. 680 next:next:t$=ti$:return
  75. 690 y=i:x=fnhz(ar(y)):pokefnme(.),0
  76. 700 y=j:x=fnhz(ar(y)):pokefnme(.),0
  77. 710 tp=ar(i):ar(i)=ar(j):ar(j)=tp
  78. 720 y=i:x=fnhz(ar(y)):cl=fncl(ar(y))*fnps(ar(y)):pokefnme(.),cl
  79. 730 y=j:x=fnhz(ar(y)):cl=fncl(ar(y))*fnps(ar(y)):pokefnme(.),cl:return
  80. 740 ti$="000000":rem 1st line of delayed selection sort
  81. 750 fori=1tomx-1:k=i:forj=i+1tomx:ifar(j)<ar(k)thenk=j
  82. 760 gosub1570:if(ab)thenj=mx:i=mx-1
  83. 770 next:gosub780:next:t$=ti$:return
  84. 780 y=i:x=fnhz(ar(y)):pokefnme(.),0
  85. 790 y=k:x=fnhz(ar(y)):pokefnme(.),0
  86. 800 tp=ar(i):ar(i)=ar(k):ar(k)=tp
  87. 810 y=i:x=fnhz(ar(y)):cl=fncl(ar(y))*fnps(ar(y)):pokefnme(.),cl
  88. 820 y=k:x=fnhz(ar(y)):cl=fncl(ar(y))*fnps(ar(y)):pokefnme(.),cl:return
  89. 830 ti$="000000":bd=mx:rem 1st line of bubble sort
  90. 840 j=0:fori=1tobd-1:ifar(i)>ar(i+1)thengosub880:j=i
  91. 850 gosub1570:if(ab)theni=bd-1:bd=0
  92. 860 next:bd=j:if(bd<>0)then840
  93. 870 t$=ti$:return
  94. 880 y=i:x=fnhz(ar(y)):pokefnme(.),0
  95. 890 y=i+1:x=fnhz(ar(y)):pokefnme(.),0
  96. 900 tp=ar(i):ar(i)=ar(i+1):ar(i+1)=tp
  97. 910 y=i:x=fnhz(ar(y)):cl=fncl(ar(y))*fnps(ar(y)):pokefnme(.),cl
  98. 920 y=i+1:x=fnhz(ar(y)):cl=fncl(ar(y))*fnps(ar(y)):pokefnme(.),cl:return
  99. 930 ti$="000000":g=int(mx/2):rem 1st line of shell sort
  100. 940 dn=-1:fori=1tomx-g:ifar(i)>ar(i+g)thengosub990:dn=0
  101. 950 gosub1570:if(ab)theni=mx-g:dn=-1:g=0
  102. 960 next:if(not dn)then940
  103. 970 g=int(g/2):ifg>0then940
  104. 980 t$=ti$:return
  105. 990 y=i:x=fnhz(ar(y)):pokefnme(.),0
  106. 1000 y=i+g:x=fnhz(ar(y)):pokefnme(.),0
  107. 1010 tp=ar(i):ar(i)=ar(i+g):ar(i+g)=tp
  108. 1020 y=i:x=fnhz(ar(y)):cl=fncl(ar(y))*fnps(ar(y)):pokefnme(.),cl
  109. 1030 y=i+g:x=fnhz(ar(y)):cl=fncl(ar(y))*fnps(ar(y)):pokefnme(.),cl:return
  110. 1040 ti$="000000":rem 1st line of heap sort
  111. 1050 fori=int(mx/2)to1step-1:l=i:r=mx:gosub1170
  112. 1060 gosub1570:if(ab)theni=1
  113. 1070 next:if(ab)then1110
  114. 1080 fori=mx-1to1step-1:gosub1120:l=1:r=i:gosub1170
  115. 1090 gosub1570:if(ab)theni=1
  116. 1100 next
  117. 1110 t$=ti$:return
  118. 1120 y=1:x=fnhz(ar(y)):pokefnme(.),0
  119. 1130 y=i+1:x=fnhz(ar(y)):pokefnme(.),0
  120. 1140 tp=ar(i+1):ar(i+1)=ar(1):ar(1)=tp
  121. 1150 y=1:x=fnhz(ar(y)):cl=fncl(ar(y))*fnps(ar(y)):pokefnme(.),cl
  122. 1160 y=i+1:x=fnhz(ar(y)):cl=fncl(ar(y))*fnps(ar(y)):pokefnme(.),cl:return
  123. 1170 j=2*l:vl=ar(l)
  124. 1180 ifj>rthen1240
  125. 1190 if(j<r)thenif(ar(j)<ar(j+1))thenj=j+1
  126. 1200 ifvl>=ar(j)then1240
  127. 1210 y=l:x=fnhz(ar(y)):pokefnme(.),0:ar(l)=ar(j)
  128. 1220 x=fnhz(ar(y)):cl=fncl(ar(y))*fnps(ar(y)):pokefnme(.),cl
  129. 1230 l=j:j=2*j:goto1180
  130. 1240 y=l:x=fnhz(ar(y)):pokefnme(.),0:ar(l)=vl
  131. 1250 x=fnhz(ar(y)):cl=fncl(ar(y))*fnps(ar(y)):pokefnme(.),cl:return
  132. 1260 ti$="000000":sl(1)=1:sr(1)=mx:pt=1:rem 1st line of quicksort
  133. 1270 l=sl(pt):r=sr(pt):pt=pt-1
  134. 1280 i=l:j=r:vl=ar((l+r)/2)
  135. 1290 ifar(i)<vltheni=i+1:goto1290
  136. 1300 ifar(j)>vlthenj=j-1:goto1300
  137. 1310 gosub1570:if(ab)then1410
  138. 1320 ifi<=jthengosub1420:i=i+1:j