Sorting algorithms/Insertion sort: Difference between revisions
Content added Content deleted
(→{{header|ALGOL 68}}: ++ awk) |
(added standard ml) |
||
Line 365: | Line 365: | ||
(insertion-sort '(6 8 5 9 3 2 1 4 7))</lang> |
(insertion-sort '(6 8 5 9 3 2 1 4 7))</lang> |
||
=={{header|Standard ML}}== |
|||
<lang sml>fun insertion_sort cmp = let |
|||
fun insert (x, []) = [x] |
|||
| insert (x, y::ys) = |
|||
case cmp (x, y) of GREATER => y :: insert (x, ys) |
|||
| _ => x :: y :: ys |
|||
in |
|||
foldl insert [] |
|||
end; |
|||
insertion_sort Int.compare [6,8,5,9,3,2,1,4,7];</lang> |
|||
=={{header|UnixPipes}}== |
=={{header|UnixPipes}}== |