bubble sort by pooq

b:?read();c:s:0;n:makelist(0,i,1,b);for i thru b do n[i]:?read();for i thru b do for j thru b-i do(c:c+1,t:n[j+1],if t<n[j]then(s:s+1,n[j+1]:n[j],n[j]:t),printf(?t,"compare = ~2d   swap = ~2d   data:~{~3d~}
",c,s,n));

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

download

return to the top page