Copyright | Copyright (C) 2021 Yoo Chung |
---|---|
License | GPL-3.0-or-later |
Maintainer | dev@chungyc.org |
Safe Haskell | Safe-Inferred |
Language | GHC2021 |
Part of Ninety-Nine Haskell Problems. Some solutions are in Solutions.P69.
Synopsis
- dotstringToTree :: String -> Maybe (Tree Char)
- treeToDotstring :: Tree Char -> String
Documentation
dotstringToTree :: String -> Maybe (Tree Char) Source #
Consider binary trees with nodes that are identified by single characters.
Such a tree can be represented by the preorder sequence of its nodes in which dots (.
)
are inserted where an empty subtree is encountered during the tree traversal.
Write a function to convert a dotstring representation into its corresponding binary tree.
Examples
>>>
dotstringToTree "xy..z0..."
Just (Branch 'x' (Branch 'y' Empty Empty) (Branch 'z' (Branch '0' Empty Empty) Empty))