[ create a new paste ] login | about

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

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

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


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


Create a new paste based on this one


Comments: