ninetynine-1.3.0: Ninety-Nine Haskell Problems
CopyrightCopyright (C) 2021 Yoo Chung
LicenseGPL-3.0-or-later
Maintainerdev@chungyc.org
Safe HaskellSafe-Inferred
LanguageGHC2021

Problems.P69

Description

Part of Ninety-Nine Haskell Problems. Some solutions are in Solutions.P69.

Synopsis

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))

treeToDotstring :: Tree Char -> String Source #

Write a function to convert a binary tree to its dotstring representation.

Examples

>>> treeToDotstring tree1
"abd..e..c.fg..."