Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
tree-node-common.H
Go to the documentation of this file.
1
2
3/*
4 Aleph_w
5
6 Data structures & Algorithms
7 version 2.0.0b
8 https://github.com/lrleon/Aleph-w
9
10 This file is part of Aleph-w library
11
12 Copyright (c) 2002-2026 Leandro Rabindranath Leon
13
14 Permission is hereby granted, free of charge, to any person obtaining a copy
15 of this software and associated documentation files (the "Software"), to deal
16 in the Software without restriction, including without limitation the rights
17 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
18 copies of the Software, and to permit persons to whom the Software is
19 furnished to do so, subject to the following conditions:
20
21 The above copyright notice and this permission notice shall be included in all
22 copies or substantial portions of the Software.
23
24 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
27 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
29 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 SOFTWARE.
31*/
32
33
34# ifndef TREE_NODE_COMMON_H
35# define TREE_NODE_COMMON_H
36
37# include <gtest/gtest.h>
38
39# include <tpl_tree_node.H>
40
41using namespace testing;
42
43
44/* Build:
45 0
46
47 1 2 3 4 5
48
496 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
50
51*/
53{
54 Tree_Node<int> * root = new Tree_Node<int>(key++);
55 for (size_t i = 0; i < num_nodes_by_subtree; ++i, ++key)
56 root->insert_rightmost_child(new Tree_Node<int>(key));
57
58 for (Tree_Node<int>::Children_Iterator it(root); it.has_curr(); it.next())
59 {
60 auto ptr = it.get_curr();
61 for (size_t i = 0; i < num_nodes_by_subtree; ++i, ++key)
62 ptr->insert_rightmost_child(new Tree_Node<int>(key));
63 }
64 return root;
65}
66
67
68// preorder traversal of sample_tree(5, 0)
69DynList<int> l = { 0, 1, 6, 7, 8, 9, 10, 2, 11, 12, 13, 14, 15, 3, 16, 17,
70 18, 19, 20, 4, 21, 22, 23, 24, 25, 5, 26, 27, 28, 29, 30 };
71
72struct Simple_Tree : public Test
73{
74 Tree_Node<int> * root = nullptr;
77};
78
79
80struct Three_Trees : public Test
81{
82 Tree_Node<int> * root1 = nullptr;
83 Tree_Node<int> * root2 = nullptr;
84 Tree_Node<int> * root3 = nullptr;
85
86 const DynList<int> l1 = { 0, 1, 6, 7, 8, 9, 10, 2, 11, 12, 13, 14, 15, 3,
87 16, 17, 18, 19, 20, 4, 21, 22, 23, 24, 25, 5, 26,
88 27, 28, 29, 30 };
89
90 const DynList<int> l2 = { 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43 };
91
92 const DynList<int> l3 = { 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56,
93 57, 58, 59, 60, 61, 62, 63, 64 };
94
96 : root1(sample_tree(5, 0)), root2(sample_tree(3, 31)),
97 root3(sample_tree(4, 44)) {}
104};
105
106
107# endif
Dynamic singly linked list with functional programming support.
Definition htlist.H:1423
Iterator over the children of this.
Generic m-ary trees.
__gmp_expr< T, __gmp_binary_expr< __gmp_expr< T, U >, unsigned long int, __gmp_root_function > > root(const __gmp_expr< T, U > &expr, unsigned long int l)
Definition gmpfrxx.h:4060
void destroy_tree(Node *root)
Destroys (frees memory) the tree whose root is root.
DynList< T > maps(const C &c, Op op)
Classic map operation.
Tree_Node< int > * root
Tree_Node< int > * root1
const DynList< int > l2
const DynList< int > l3
const DynList< int > l1
Tree_Node< int > * root2
Tree_Node< int > * root3
General tree (n-ary tree) node.
Tree_Node< int > * sample_tree(size_t num_nodes_by_subtree, int key)
DynList< int > l