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.P70

Description

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

Synopsis

Documentation

stringToMultitree :: String -> Maybe (MultiwayTree Char) Source #

We suppose that the nodes of a multiway tree contain single characters. The characters in the node string are in depth-first order of the tree. The special character ^ is inserted whenever the move is a backtrack to the previous level during tree traversal. Note that the tree traversal will also backtrack from the root node of the tree.

For example, multitree5 is represented by the string "afg^^c^bd^e^^^".

Write a function to construct the MultiwayTree when the string is given.

Examples

>>> stringToMultitree "afg^^c^bd^e^^^" == Just multitree5
True

multitreeToString :: MultiwayTree Char -> String Source #

Construct the node string from a MultiwayTree.

Examples

>>> multitreeToString multitree5
"afg^^c^bd^e^^^"