Last active
January 31, 2021 11:29
-
-
Save evgenii-malov/8dd9fe486883da7f936056819cfde289 to your computer and use it in GitHub Desktop.
level order traversal with bfs
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
-- see video https://www.youtube.com/watch?v=OibwXW1ssV8 | |
-- pretty print tree https://www.youtube.com/watch?v=Ud-1Z0hBlB8 | |
data Btree a = Empty | Node a (Btree a) (Btree a) deriving Show | |
tr_l = Node "b" (Node "d" Empty Empty) (Node "e" Empty Empty) | |
tr_r = Node "c" (Node "f" Empty Empty) (Node "g" Empty Empty) | |
--tr = Node "a" tr_l tr_r :: Btree String | |
tr_ll = Node "x" tr_l Empty | |
tr = Node "a" tr_ll tr_r :: Btree String | |
lev_ord t = lo [t] | |
where lo :: [Btree a] -> [a] | |
lo [] = [] | |
lo (Empty:xs) = lo xs | |
lo (Node v l r:xs) = v : lo (xs ++ [l,r]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Videos:
pretty print tree
Level order traversal with BFS
Level order traversall with all paths
Level order traversall with zipwith
Level order traversall with label tree
Level order traversal of binary tree with fmap