Problem 69 Solution

dotToTree : String -> (Tree Char, String)
dotToTree s = 
    let 
        (x, xs) = Maybe.withDefault ('.', "") <| String.uncons s
    in
        case x of
            '.' ->
                (Empty, xs)

            _ ->
                let 
                    (treeL, restL) = dotToTree xs
                    (treeR, restR) = dotToTree restL
                in 
                    (Node x treeL treeR, restR)


treeToDot : Tree Char -> String
treeToDot tree = 
    case tree of
        Empty ->
            "."

        Node v l r ->
            String.fromChar v ++ treeToDot l ++ treeToDot r

Back to problem

results matching ""

    No results matching ""