bubble sort by ksk

_,*a=$<.map{|_|"%3d"%_}
_=$.-2
c=s=0
a.map{_.times{|_|puts"compare =%3d   swap =%3d   data:%s"%[c+=1,s+=(x=a[_,2])<=>a[_,2]=x.sort,a]}}

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

download

return to the top page