Skip to content

Instantly share code, notes, and snippets.

@joaomilho
Created March 24, 2013 02:13
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 joaomilho/5230162 to your computer and use it in GitHub Desktop.
Save joaomilho/5230162 to your computer and use it in GitHub Desktop.
merge [] ys = ys
merge xs [] = xs
merge (x:xs) (y:ys) = if x <= y
then x : merge xs (y:ys)
else y : merge (x:xs) ys
mergesort [] = []
mergesort [x] = [x]
mergesort xs = let (as, bs) = splitAt (length xs `quot` 2) xs
in merge (mergesort as) (mergesort bs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment