Sorting algorithms/Insertion sort: Difference between revisions
Content added Content deleted
Basicgames (talk | contribs) |
Not a robot (talk | contribs) (Add Miranda) |
||
Line 3,463: | Line 3,463: | ||
#(2, 2, 5, 6, 9, 10, 15, 18, 22, 22, 23, 24, 26, 27, 28, 31, 33, 34, 35, 40) |
#(2, 2, 5, 6, 9, 10, 15, 18, 22, 22, 23, 24, 26, 27, 28, 31, 33, 34, 35, 40) |
||
</syntaxhighlight> |
</syntaxhighlight> |
||
=={{header|Miranda}}== |
|||
<syntaxhighlight lang="miranda">main :: [sys_message] |
|||
main = [Stdout ("Before: " ++ show testlist ++ "\n"), |
|||
Stdout ("After: " ++ show (insertionsort testlist) ++ "\n")] |
|||
where testlist = [4,65,2,-31,0,99,2,83,782,1] |
|||
insertionsort :: [*]->[*] |
|||
insertionsort = foldr insert [] |
|||
insert :: *->[*]->[*] |
|||
insert x [] = [x] |
|||
insert x (y:ys) = x:y:ys, if x<y |
|||
= y:insert x ys, otherwise</syntaxhighlight> |
|||
{{out}} |
|||
<pre>Before: [4,65,2,-31,0,99,2,83,782,1] |
|||
After: [-31,0,1,2,2,4,65,83,99,782]</pre> |
|||
=={{header|ML}}== |
=={{header|ML}}== |