bubble sort by tabasa

n=gets.to_i
a=[]
while gets
a<<$_.to_i
end
s=t=0
n.times{|k|
(n-k-1).times{|o|
a[o]>a[o+1]?(a[o],a[o+1]=a[o+1],a[o];s+=1):0
printf"compare = %2d   swap = %2d   data:"+" %2d"*n,t+=1,s,*a
puts}}

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

download

return top