Created
May 19, 2012 17:14
-
-
Save rhysd/2731557 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mergeSort :: Ord a => [a] -> [a] | |
mergeSort [] = [] | |
mergeSort [x] = [x] | |
mergeSort xs = merge (mergeSort l) (mergeSort r) | |
where | |
s = length xs `div` 2 | |
(l,r) = splitAt s xs | |
merge :: Ord a => [a] -> [a] -> [a] | |
merge [] ys = ys | |
merge xs [] = xs | |
merge (x:xs) (y:ys) | x<=y = x:merge xs (y:ys) | |
| x>y = y:merge (x:xs) ys | |
main = do | |
print $ mergeSort [4,1,3,6,7,3,2] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment