bubble sort by leonid

c=w=0
s,*d=$<.map &:to_i
s.times{|i|puts"compare =%3d   swap =%3d   data:"%[c+=1,w+=(f=d[i,2])<=>d[i,2]=f.sort]+"%3d"*~-$.%d}while 0<s-=1

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

download

return to the top page