Last active
October 5, 2016 07:45
-
-
Save hsinewu/a1fab5d79d67782016add112a319b793 to your computer and use it in GitHub Desktop.
Merge sort in haskell
This file contains hidden or 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 [] = error "Empty list" | |
mergesort [x] = [x] | |
mergesort xs = | |
merge (mergesort left) (mergesort right) | |
where | |
(left,right) = splitAt (length xs `div` 2) xs | |
merge [] ys = ys | |
merge xs [] = xs | |
merge xs@(x:xs') ys@(y:ys') | |
| x<=y = x: merge xs' ys | |
| otherwise = y: merge xs ys' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment