Created
May 6, 2013 20:37
-
-
Save booo/5527996 to your computer and use it in GitHub Desktop.
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
| import Data.List | |
| data STree a = Empty | Node (STree a) a (STree a) | |
| deriving (Eq, Ord, Show) | |
| bft :: [STree a] -> [[a]] | |
| bft = unfoldr f | |
| where f x = case x of | |
| [] -> Nothing | |
| (Empty):xs -> Just ([], xs) | |
| (Node l v r):xs -> Just ([v], xs ++ [l] ++ [r]) | |
| t = Node (Node (Node Empty 1 Empty) 1 (Node (Node Empty 2 Empty) 2 Empty)) | |
| 3 | |
| (Node (Node Empty 5 Empty) 8 Empty) | |
| t2 = Node Empty 2 Empty | |
| -- bft [t] == [[3],[1,8],[1,2,5],[2],[]] | |
| -- tl = (Node (Node Empty 1 Empty) 1 (Node (Node Empty 2 Empty) 2 Empty)) | |
| -- tr = (Node (Node Empty 5 Empty) 8 Empty) | |
| -- bft [tl, tr] == [[1,8],[1,2,5],[2],[]] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment