Sorting algorithms/Insertion sort: Difference between revisions
Content added Content deleted
m (→{{header|Pascal}}: cosmetic) |
(→OCaml: clean-up & simplify) |
||
Line 3,727: | Line 3,727: | ||
=={{header|OCaml}}== |
=={{header|OCaml}}== |
||
<syntaxhighlight lang="ocaml">let rec insert lst x = |
<syntaxhighlight lang="ocaml">let rec insert lst x = |
||
match lst with |
match lst with |
||
| y :: ys when x > y -> y :: insert ys x |
|||
| |
| _ -> x :: lst |
||
| y :: ys -> y :: insert ys x |
|||
⚫ | |||
;; |
|||
⚫ | |||
let () = [6; 8; 5; 9; 3; 2; 1; 4; 7] |
|||
|> insertion_sort |> List.iter (Printf.printf " %u") |> print_newline</syntaxhighlight> |
|||
{{out}} |
|||
<pre> 1 2 3 4 5 6 7 8 9</pre> |
|||
=={{header|Oforth}}== |
=={{header|Oforth}}== |