bubble sort by yowa

n,*a=$<.map(&:to_i)
i=c=0
eval'(m-=1).times{|y|e,f=a[y,2]
e>f&&(c+=1;a[y,2]=f,e)
puts %w(compare swap data:)*" =%3d   "%[i+=1,c]+"%3d"*n%a}
'*m=n

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

download

return to the top page