Created
May 12, 2012 16:50
-
-
Save mmagm/2667574 to your computer and use it in GitHub Desktop.
haskell merge sort
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
import Data.List | |
merge :: Ord a => [a] -> [a] -> [a] | |
merge x [] = x | |
merge [] y = y | |
merge (x:xs) (y:ys) = case compare x y of | |
LT -> x : merge xs (y:ys) | |
_ -> y : merge (x:xs) ys | |
mergesort :: Ord a => [a] -> [a] | |
mergesort [x] = [x] | |
mergesort list = merge left right where | |
split = splitAt (length list `div` 2) list | |
left = mergesort $ fst $ split | |
right = mergesort $ snd $ split |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment