home *** CD-ROM | disk | FTP | other *** search
/ Commodore Disc 35 / Commodore_Disc_35_19xx_-_de.d64 / quick-sort.int (.txt) < prev    next >
Commodore BASIC  |  2022-10-26  |  682b  |  23 lines

  1. 100 input"anzahl der werte";d:print
  2. 110 dim e%(d),a%(d),l%(16),r%(16)
  3. 120 fori=1tod:e%(i)=int(rnd(1)*32768):a%(i)=e%(i):next
  4. 130 at=ti:gosub 190:at=ti-at
  5. 140 fori=1tod:printe%(i),a%(i):next
  6. 150 print:printat:end
  7. 160 rem ------------------------------
  8. 170 rem   quicksort 128 integer
  9. 180 rem ------------------------------
  10. 190 l%(1)=1:r%(1)=d:eb=2
  11. 200 eb=eb-1:ifeb=0thenreturn
  12. 210 if l%(eb)>=r%(eb) then 200
  13. 220 l=l%(eb):r=r%(eb):vw=a%(int((l+r)/2))
  14. 230 if a%(l)<vw then l=l+1:goto230
  15. 240 ifa%(r)>vw then r=r-1:goto240
  16. 250 ifl>r then 280
  17. 260 a=a%(l):a%(l)=a%(r):a%(r)=a
  18. 270 l=l+1:r=r-1:ifl<=rthen230
  19. 280 eb=eb+1
  20. 290 if(r-l%(eb-1))<(r%(eb-1)-l)thenl%(eb)=l%(eb-1):r%(eb)=r:l%(eb-1)=l:goto210
  21. 300 l%(eb)=l:r%(eb)=r%(eb-1):r%(eb-1)=r:goto210
  22. 310 rem ------------------------------
  23.