Sorting algorithms/Bubble sort: Difference between revisions

no edit summary
(Added Clean example)
No edit summary
Line 257:
print join(",", Bubble_Sort(@test));
</highlightSyntax>
 
 
==[[Pop11]]==
[[Category:Pop11]]
 
define bubble_sort(v);
lvars n=length(v), done=false, i;
while not(done) do
true -> done;
for i from 1 to n - 1 do
if v(i) > v(i+1) then
false -> done;
;;; Swap using multiple assignment
(v(i+1), v(i)) -> (v(i), v(i+1));
endif;
endfor;
endwhile;
enddefine;
;;; Test it
vars ar = { 10 8 6 4 2 1 3 5 7 9};
bubble_sort(ar);
ar =>
 
==[[Python]]==
Anonymous user