Saturday, October 23, 2010

Bubble sort

fastgraphics : Dim a(32): flag=1
For n = 1 to 30
a[n]=int(rand*20+1)
next n
while flag=1
flag=0
For n = 1 to 30
clg
For w = 1 to 30
text 15,10*w,a[w]
rect 40,10*w,a[w]*10,7
next w
pause .01
refresh
if a[n]> a[n+1] then
x=a[n]
a[n]=a[n+1]
a[n+1]=x
flag=1
end if
next n
end while