Sorting algorithms/Insertion sort: Difference between revisions

→‎OCaml: clean-up & simplify
(→‎OCaml: clean-up & simplify)
Line 3,727:
 
=={{header|OCaml}}==
<syntaxhighlight lang="ocaml">let rec insert lst x =
match lst with
| y []:: ys when x > y -> [y :: insert ys x]
| y :: ys when x <= y_ -> x :: y :: yslst
| y :: ys -> y :: insert ys x
 
let insertion_sort = List.fold_left insert [];;
;;
let insertion_sort = List.fold_left insert [];;
 
insertion_sortlet () = [6; 8; 5; 9; 3; 2; 1; 4; 7];;</syntaxhighlight>
|> insertion_sort |> List.iter (Printf.printf " %u") |> print_newline</syntaxhighlight>
{{out}}
<pre> 1 2 3 4 5 6 7 8 9</pre>
 
=={{header|Oforth}}==
559

edits