bubble sort by murky-satyr

r=io.read
d={}n=r()c=0 s=0
for i=1,n do
d[i]=0+r()end
for i=1-n,0 do
for j=1,-i do
t=d[j+1]if t<d[j]then d[j],d[j+1]=t,d[j]s=s+1 end
c=c+1
print(('compare =%3s   swap =%3s   data:'..('%3s'):rep(n)):format(c,s,unpack(d)))end
end

Note that non-ascii characters in the above source code will be escaped (such as \x9f).

download

return to the top page