Skip to content

Instantly share code, notes, and snippets.

@AlexMost
Last active August 29, 2015 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AlexMost/a1f24bb0216088f37228 to your computer and use it in GitHub Desktop.
Save AlexMost/a1f24bb0216088f37228 to your computer and use it in GitHub Desktop.
-- 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]
@pavlo-v-chernykh
Copy link

@AlexMost
Copy link
Author

thx )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment