home *** CD-ROM | disk | FTP | other *** search
- 0 poke646,0:poke53280,12:poke53281,12
- 1 rem ==================================
- 2 rem demonstration of quicksort by
- 3 rem ivan rudyk
- 4 rem ==================================
- 10 q=180 : dim n(q),m(q)
- 20 print"[147]generating numbers...":for x=1 to q:n(x)=int(1000*rnd(0))+1:next x
- 30 print"sorting..." : t0=ti
- 40 m(1)=1 : m(2)=q : a=2
- 50 b=m(a) : a=a-1 : c=m(a) : a=a-1 : e=c
- 60 f=b : d=n((c+b)/2)
- 70 if n(e)<d then e=e+1 : goto 70
- 80 if n(f)>d then f=f-1 : goto 80
- 90 if e<=f then z=n(e) : n(e)=n(f) : n(f)=z : e=e+1 : f=f-1
- 100 if e<=f then 70
- 110 if c<f then a=a+1 : m(a)=c : a=a+1 : m(a)=f
- 120 c=e : if c<b then 60
- 130 if a<>0 then 50
- 140 for x=1 to q : print n(x); : next x
- 145 print ti-t0"jiffies" : end
- 200 rem ================================
- 210 rem conventional bubble sort
- 220 rem (add line 35 goto 240)
- 230 rem ================================
- 240 for j=1 to q-1 :for k=j+1 to q : if n(j)>n(k) then t=n(j) :n(j)=n(k) :n(k)=t
- 250 next k,j : for x=1 to q : print n(x); : next x : print ti-t0"jiffies" : end
-