Last active

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist
View mergesort.hs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
-- mergesort
merge:: (Ord a) => [a] -> [a] -> [a]
merge xs [] = xs
merge [] ys = ys
merge f@(x:xs) s@(y:ys)
| x > y = x: merge xs s
| x < y = y: merge f ys
| x == y = x: y: merge xs ys
 
 
mergeSort:: (Ord a) => [a] -> [a]
mergeSort [x] = [x]
mergeSort lst =
merge (mergeSort first) (mergeSort last)
where
(first, last) = splitAt (quot (length lst) 2) lst
 
 
-- | The main entry point.
main :: IO ()
main = do
putStrLn $ show $ mergeSort [3, 2, 1, 4, 4]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.