Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Prelude hiding (Left, Right)
- data Tree a = Empty | Node a (Tree a) (Tree a) deriving (Show)
- data Direction = Left | Right
- computeZigzag::Tree a->Int->Direction->[Int]
- computeZigzag Empty _ _ = [0]
- computeZigzag (Node _ Empty Empty) current _ = [current]
- computeZigzag (Node _ left right) current Left = computeZigzag left current Left ++ computeZigzag right (current + 1) Right
- computeZigzag (Node _ left right) current Right = computeZigzag left (current + 1) Left ++ computeZigzag right current Right
- zigzag::Tree a->Int
- zigzag (Node _ left right) = maximum(computeZigzag left 0 Left ++ computeZigzag right 0 Right)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement