bubble sort by nn

for(a=[m=-1];j=readline(S=' ');)a[m++]=j>9?j:S+j
for(s=0;m--;)for(i=0;i<m;print('compare =',++j>9?j:S+j,'  swap =',s>9?s:S+s,'  data:',a.join(S)))s+=v=(c=a[i])>(a[i]=a[++i]),a[i-!v]=c

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

download

return to the top page