bubble sort by uru

var a:array[byte]of comp;c,s,i,j,n,t:comp;begin
read(n);for i:=1to n do read(a[i]);for i:=1to n-1do for j:=1to n-i do begin
inc(c);if a[j+1]<a[j]then begin
inc(s);t:=a[j];a[j]:=a[j+1];a[j+1]:=t;end;write('compare =',c:3,'swap =':9,s:3,'data:':8);for t:=1to n do write(a[t]:3);writeln;end;end.

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

download

return to the top page