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

Description

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

Synopsis

Documentation

inorder :: Tree a -> [a] Source #

Return the in-order sequence of a binary tree.

Examples

>>> inorder tree1
"dbeacgf"

preorder :: Tree a -> [a] Source #

Return the pre-order sequence of a binary tree.

Examples

>>> preorder tree1
"abdecfg"

ordersToTree Source #

Arguments

:: Eq a 
=> [a]

In-order sequence

-> [a]

Pre-order sequence

-> Maybe (Tree a)

Binary tree with the given in-order and pre-order sequences

Given the in-order and pre-order sequences of a binary tree, return the original binary tree.

The values in each node of the binary tree will be distinct, in which case the tree is determined unambiguously.

Examples

>>> ordersToTree "dbeacgf" "abdecfg" == Just tree1
True