Last active
August 29, 2015 14:13
-
-
Save fernandezpablo85/78ed53c1238b826622fe 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
module MergeSort(sort) where | |
sort :: (Ord a) => [a] -> [a] | |
sort [] = [] | |
sort [a] = [a] | |
sort as = merge (sort firstHalf) (sort secondHalf) | |
where | |
(firstHalf, secondHalf) = splitAt half as | |
half = (pred . length) as | |
merge :: (Ord a) => [a] -> [a] -> [a] | |
merge as [] = as | |
merge [] bs = bs | |
merge (a:as) (b:bs) = if (a < b) | |
then a : merge as (b:bs) | |
else b : merge (a:as) bs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment