Created
April 18, 2011 21:34
-
-
Save KengoTODA/926236 to your computer and use it in GitHub Desktop.
merge sort v2
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
| fastMergeSort :: (Ord a) => [a] -> [a] | |
| fastMergeSort xs = fastMergeSort' (length xs) xs | |
| where | |
| fastMergeSort' 0 [] = [] | |
| fastMergeSort' 1 [x] = [x] | |
| fastMergeSort' s xs = merge (fastMergeSort' i l) (fastMergeSort' j r) | |
| where | |
| i = s `div` 2 | |
| j = s - i | |
| l = take i xs | |
| r = drop i xs | |
| merge x [] = x | |
| merge [] y = y | |
| 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