Sorting algorithms/Bubble sort: Difference between revisions

m (→‎{{header|Icon}}: typo fix)
Line 1,410:
var array integer: arr is [] (3, 78, 4, 23, 6, 8, 6);
bubbleSort(arr);</lang>
 
=={{header|Sather}}==
<lang sather>class SORT{T < $IS_LT{T}} is
private swap(inout a, inout b:T) is
temp ::= a;
a := b;
b := temp;
end;
bubble_sort(inout a:ARRAY{T}) is
i:INT;
if a.size < 2 then return; end;
loop
sorted ::= true;
loop i := 0.upto!(a.size - 2);
if a[i+1] < a[i] then
swap(inout a[i+1], inout a[i]);
sorted := false;
end;
end;
until!(sorted);
end;
end;
end;</lang>
 
<lang sather>class MAIN is
main is
a:ARRAY{INT} := |10, 9, 8, 7, 6, -10, 5, 4|;
SORT{INT}::bubble_sort(inout a);
#OUT + a + "\n";
end;
end;</lang>
 
This should be able to sort (in ascending order) any object for which <code>is_lt</code> (less than) is defined.
 
=={{header|Smalltalk}}==