Copyright | Copyright (C) 2023 Yoo Chung |
---|---|
License | GPL-3.0-or-later |
Maintainer | dev@chungyc.org |
Safe Haskell | Safe-Inferred |
Language | GHC2021 |
Supporting definitions for multiway tree problems.
Synopsis
- data MultiwayTree a = MultiwayTree a [MultiwayTree a]
- multitree1 :: MultiwayTree Char
- multitree2 :: MultiwayTree Char
- multitree3 :: MultiwayTree Char
- multitree4 :: MultiwayTree Char
- multitree5 :: MultiwayTree Char
- multitreeSize :: MultiwayTree a -> Int
Documentation
data MultiwayTree a Source #
A multiway tree is composed of a root element and a (possibly empty) set of successors which are multiway trees themselves. A multiway tree is never empty. The set of successor trees is sometimes called a forest.
MultiwayTree a [MultiwayTree a] |
Instances
multitree1 :: MultiwayTree Char Source #
Example of the following multiway tree.
>>>
multitree1 == MultiwayTree 'a' []
True
multitree2 :: MultiwayTree Char Source #
Example of the following multiway tree.
>>>
multitree2 == MultiwayTree 'a' [MultiwayTree 'b' []]
True
multitree3 :: MultiwayTree Char Source #
Example of the following multiway tree.
>>>
multitree3 == MultiwayTree 'a' [MultiwayTree 'b' [MultiwayTree 'c' []]]
True
multitree4 :: MultiwayTree Char Source #
Example of the following multiway tree.
>>>
multitree4 == MultiwayTree 'b' [MultiwayTree 'd' [], MultiwayTree 'e' []]
True
multitree5 :: MultiwayTree Char Source #
Example of the following multiway tree.
>>>
:{
multitree5 == MultiwayTree 'a' [ MultiwayTree 'f' [MultiwayTree 'g' []] , MultiwayTree 'c' [] , MultiwayTree 'b' [MultiwayTree 'd' [], MultiwayTree 'e' []] ] :} True
multitreeSize :: MultiwayTree a -> Int Source #
Returns the number of nodes in a multiway tree.
Examples
>>>
multitreeSize multitree1
1
>>>
multitreeSize multitree5
7
Notes
This was originally problem 70C. This is not included as a problem, to avoid a numbering conflict with the somewhat unrelated problem 70 in the original list, which is more interesting.