blob: 69f42f566ad3c9212b803c5e2d74af3cb668c83a (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
data Tree a = Node a [Tree a] deriving (Eq, Show)
stringToTree :: [Char] -> Tree Char
stringToTree l = fst $ build l
where build (x:xs) = (Node x chd'', xs'')
where loop ('^':xs) = ([], xs)
loop xs = (chd':c, x)
where (chd', xs') = build xs
(c, x) = loop xs'
(chd'', xs'') = loop xs
treeToString :: Tree Char -> [Char]
treeToString (Node v xs) = v:(concat $ map treeToString xs) ++ "^"
|