Anonymous user
Sorting algorithms/Comb sort: Difference between revisions
added ocaml
(Created the article and added Java, ti83b, and C++) |
(added ocaml) |
||
Line 74:
}
}</lang>
=={{header|OCaml}}==
<lang ocaml>let comb_sort ~input =
let input_length = Array.length input in
let gap = ref(input_length) in
let swapped = ref true in
while (!gap > 1 || !swapped) do
if (!gap > 1) then
gap := int_of_float (float !gap /. 1.3);
let i = ref 0 in
swapped := false;
while (!i + !gap < input_length) do
if input.(!i) > input.(!i + !gap) then begin
let tmp = input.(!i) in
input.(!i) <- input.(!i + !gap);
input.(!i + !gap) <- tmp;
swapped := true;
end;
incr i;
done
done
;;</lang>
=={{header|TI-83 BASIC}}==
|