Jump to content

Sorting algorithms/Insertion sort: Difference between revisions

Add Miranda
(Add Miranda)
Line 3,463:
#(2, 2, 5, 6, 9, 10, 15, 18, 22, 22, 23, 24, 26, 27, 28, 31, 33, 34, 35, 40)
</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}}==
2,093

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.