Skip to content

@AlexMost /mergesort.hs
Last active

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
-- 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]
@AlexMost
Owner

thx )

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.