bubble sort by notogawa

main=interact$g[][1,0][].tail.map f.lines
f[x]=[' ',x];f x=x
g x[n,s]y(a:b:z)=unwords("compare =":h n:"  swap =":h e:"  data:":x++c:d:z++y)++'\n':g(x++[c])[n+1,e]y(d:z)where(c,d,e)|b<a=(b,a,s+1)|0<1=(a,b,s)
g x n y z|z>x=g[]n(z++y)x|0<1=[]
h=f.show

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

download

return to the top page