Sorting algorithms/Insertion sort: Difference between revisions
Content added Content deleted
(→{{header|Prolog}}: Added spaces to have one verbatim block) |
(added ocaml) |
||
Line 117: | Line 117: | ||
} |
} |
||
} |
} |
||
=={{header|OCaml}}== |
|||
let rec insert x = function |
|||
[] -> [x] |
|||
| y :: ys -> |
|||
if x <= y then x :: y :: ys |
|||
else y :: insert x ys |
|||
;; |
|||
let insertion_sort lst = List.fold_right insert lst [];; |
|||
insertion_sort [6;8;5;9;3;2;1;4;7];; |
|||
=={{header|Prolog}}== |
=={{header|Prolog}}== |