Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- linked binary tree with characters in the nodes
- data Tree = Empty | Node Char Tree Tree
- deriving (Show, Eq)
- -- input as a Tree
- input = Node 'a' (Node 'b' (Node 'd' (Node 'g' Empty Empty) (Node 'h' Empty Empty))
- (Node 'e' Empty Empty))
- (Node 'c' (Node 'f' Empty Empty) Empty)
- -- solution
- pivot Empty = Empty
- pivot (Node c l r) = go l (Node c Empty r)
- where go Empty rest = rest
- go (Node c l r) rest = go l (Node c r rest)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement