Last active
August 29, 2015 14:15
-
-
Save ibab/5363d49740722878a62b to your computer and use it in GitHub Desktop.
Merge sorted sublists into sorted list
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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