Jump to content

Sorting algorithms/Bubble sort: Difference between revisions

Added Oz example.
(Added Oz example.)
Line 889:
<lang octave>v = [9,8,7,3,1,100];
disp(bubblesort(v));</lang>
 
=={{header|Oz}}==
<lang oz>declare
proc {BubbleSort Arr}
proc {Swap I J}
Arr.J := (Arr.I := Arr.J) %% assignment returns the old value
end
IsSorted = {NewCell false}
in
for until:@IsSorted do
IsSorted := true
for I in {Array.low Arr}..{Array.high Arr}-1 do
if Arr.I > Arr.(I+1) then
IsSorted := false
{Swap I I+1}
end
end
end
end
Arr = {Tuple.toArray unit(10 9 8 7 6 5 4 3 2 1)}
in
{BubbleSort Arr}
{Inspect Arr}</lang>
 
=={{header|Perl}}==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.