[ create a new paste ] login | about

Link: http://codepad.org/CK2oKjpo    [ raw code | output | fork ]

edvakf - Haskell, pasted on Nov 30:
1
2
3
4
5
6
7
8
insertionSort [] = []
insertionSort (x:xs) = fst $ foldl (\(os,m) n -> if m > n then ((insert os n), m) else (os++[n], n)) ([x], x) xs

insert os u = ls ++ (u:hs)
    where
        (ls, hs) = span (< u) os

main = print $ insertionSort [3,4,5,3,2,1,4]


Output:
1
[1,2,3,3,4,4,5]


Create a new paste based on this one


Comments: