Skip to content

Instantly share code, notes, and snippets.

@msysyamamoto
Created October 21, 2012 05:00
Show Gist options
  • Save msysyamamoto/3925899 to your computer and use it in GitHub Desktop.
Save msysyamamoto/3925899 to your computer and use it in GitHub Desktop.
insertion sort
import Data.List
import Test.QuickCheck
insertionSort :: Ord a => [a] -> [a]
insertionSort = foldr isort []
where
isort x [] = [x]
isort x (y:ys)
| x > y = y : isort x ys
| otherwise = x : y : ys
prop_insertionSort :: [Int] -> Bool
prop_insertionSort xs = insertionSort xs == sort xs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment