Sorting algorithms/Comb sort: Difference between revisions

m (fixed the pseudocode according to discussion page)
(→‎{{header|Ruby}}: ++ sather)
Line 519:
results in
<pre>[12, 14, 23, 24, 24, 31, 35, 38, 46, 51, 57, 57, 58, 76, 78, 89, 92, 95, 97, 99]</pre>
 
=={{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;
 
-- ---------------------------------------------------------------------------------
comb_sort(inout a:ARRAY{T}) is
gap ::= a.size;
swapped ::= true;
loop until!(gap <= 1 and ~swapped);
if gap > 1 then
gap := (gap.flt / 1.25).int;
end;
i ::= 0;
swapped := false;
loop until! ( (i + gap) >= a.size );
if (a[i] > a[i+gap]) then
swap(inout a[i], inout a[i+gap]);
swapped := true;
end;
i := i + 1;
end;
end;
end;
end;
 
class MAIN is
main is
a:ARRAY{INT} := |88, 18, 31, 44, 4, 0, 8, 81, 14, 78, 20, 76, 84, 33, 73, 75, 82, 5, 62, 70|;
b ::= a.copy;
SORT{INT}::comb_sort(inout b);
#OUT + b + "\n";
end;
end;</lang>
 
=={{header|Tcl}}==