Sorting algorithms/Counting sort: Difference between revisions

added ocaml version for arrays; maybe someone else can add one for lists
(added ocaml version for arrays; maybe someone else can add one for lists)
Line 297:
Sorted: 10 20 30 40 50 60 70 80
</pre>
 
=={{header|OCaml}}==
For arrays:
<lang ocaml>let counting_sort_array arr lo hi =
let count = Array.make (hi-lo+1) 0 in
Array.iter (fun i -> count.(i-lo) <- count.(i-lo) + 1) arr;
Array.concat (Array.to_list (Array.mapi (fun i x -> Array.make x (lo+i)) count))</lang>
 
=={{header|Octave}}==
Anonymous user