Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- stringBuilder :: Tree -> [Char] -> [Char]
- stringBuilder t s =
- let c = fst (decode t s)
- xs = snd (decode t s)
- in c ++ (stringBuilder t xs)
- -- Recursively builds the output string by traversing
- -- the tree built in parse.
- decode :: Tree -> [Char] -> ([Char], [Char])
- decode (Leaf c) (x:xs) = ([c], xs)
- decode (Leaf c) [] = ([c], [])
- decode (Branch a b) (x:xs) =
- if x == '0'
- then decode a (x:xs)
- else if x == '1'
- then decode b (x:xs)
- else undefined
- decode (Branch a b) [] = ([], [])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement