Skip to content

Instantly share code, notes, and snippets.

@ibab
Last active August 29, 2015 14:15
Show Gist options
  • Save ibab/5363d49740722878a62b to your computer and use it in GitHub Desktop.
Save ibab/5363d49740722878a62b to your computer and use it in GitHub Desktop.
Merge sorted sublists into sorted list
merge [] ys = ys
merge xs [] = xs
merge xs@(x:xt) ys@(y:yt) | x <= y = x : merge xt ys
| otherwise = y : merge xs yt
mergeLists [] = []
mergeLists [x] = [x]
mergeLists (x:y:rest) = mergeLists $ (merge x y) : mergeLists rest
ll = [[1,2,3], [1,3,6], [1, 10], [3,3,3], [1], [1,1,1,5]]
main = print $ head $ mergeLists ll
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment