blob: 63c75b0c93b796eb544ea712bfe3aca012c42bce (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
data Tree a = Empty | Branch a (Tree a) (Tree a) deriving (Show, Eq)
ds2tree :: [Char] -> Tree Char
ds2tree l = fst $ build l
where build ('.':xs) = (Empty, xs)
build (x:xs) = (Branch x lt rt, xs'')
where (lt, xs') = build xs
(rt, xs'') = build xs'
tree2ds :: Tree Char -> [Char]
tree2ds Empty = "."
tree2ds (Branch x l r) = x:tree2ds l ++ tree2ds r
|