bubble sort by pooq

b:=(n:=File standardInput readLines map(asNumber))at(c:=s:=0)
for(i,1,b,for(j,1,b-i,c=c+1
t:=n at(j+1)
if(n at(j)>t,s=s+1
n atPut(j+1,n at(j))
n atPut(j,t))
write("compare =",c asString(3,0),"   swap =",s asString(3,0),"   data:")
for(k,1,b,n at(k)asString(3,0)print)
"
"print))

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

download

return to the top page