99#include <tclap/CmdLine.h>
108using namespace Aleph;
125 cout <<
"Node " <<
prefix[i++];
128 cout <<
"." <<
prefix[i++];
130 cout <<
" \"" << p->
get_key() <<
"\"" << endl;
132 if (
static_cast<size_t>(len) >=
dim)
154 const size_t dim = 10 *
h;
170 cout <<
" " << node->get_key();
180 const int rd = 1 +
static_cast<int>(1.0 * n * rand() / (RAND_MAX + 1.0));
200int main(
int argc,
char *argv[])
204 TCLAP::CmdLine
cmd(
"Deway numbering example for trees",
' ',
"1.0");
206 TCLAP::ValueArg<int> nArg(
"n",
"nodes",
"Number of nodes in the tree",
false, 10,
"int");
209 TCLAP::ValueArg<unsigned int> seedArg(
"s",
"seed",
"Random seed (0 = use time)",
false, 0,
213 cmd.parse(argc, argv);
215 int n = nArg.getValue();
216 unsigned int t = seedArg.getValue();
223 cout <<
"Deway Numbering Example" << endl;
224 cout <<
"=======================" << endl;
225 cout <<
"Parameters: n=" << n <<
", seed=" << t << endl << endl;
230 cout <<
"Binary tree (preorder):";
232 cout << endl << endl;
234 cout <<
"Binary tree (inorder):";
236 cout << endl << endl;
241 cout <<
"Forest (preorder):";
243 cout << endl << endl;
245 cout <<
"Forest (postorder):";
247 cout << endl << endl;
252 cout <<
"Conversion verification: PASSED" << endl << endl;
255 cout <<
"Deway Numbering:" << endl;
256 cout <<
"----------------" << endl;
264 cout << endl <<
"Done." << endl;
266 catch (TCLAP::ArgException &e)
268 cerr <<
"Error: " << e.error() <<
" for arg " << e.argId() << endl;
Exception handling system with formatted messages for Aleph-w.
#define ah_overflow_error_if(C)
Throws std::overflow_error if condition holds.
WeightedDigraph::Node Node
Node for binary search tree.
Forward declaration used by CRTP helpers before the full node definition.
Tree_Node * get_left_child() const noexcept
Returns the leftmost child of this.
Tree_Node * get_right_sibling() const noexcept
Returns the right sibling of this.
T & get_key() noexcept
Returns a modifiable reference to the node contents.
void deway(Tree_Node< int > *p, int prefix[], const int &len, const size_t &dim)
Recursively compute and print Deway numbering for a tree node.
static void printNode(Node *node, int, int)
BinNode< int > * random_tree(int l, int r)
Recursively build a random binary search tree.
int random_int(int l, int r)
Generate a random integer in range [l, r].
Tree visualization and output generation.
__gmp_expr< typename __gmp_resolve_expr< T, V >::value_type, __gmp_binary_expr< __gmp_expr< T, U >, __gmp_expr< V, W >, __gmp_dim_function > > dim(const __gmp_expr< T, U > &expr1, const __gmp_expr< V, W > &expr2)
__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)
int preOrderRec(Node *root, void(*visitFct)(Node *, int, int))
Traverse recursively in preorder a binary tree.
void forest_postorder_traversal(Node *root, void(*visitFct)(Node *, int, int))
Postorder traversal of a forest.
void destroy_forest(Node *root)
Destroys (frees memory) the forest whose first tree is root.
int inOrderRec(Node *root, void(*visitFct)(Node *, int, int))
Traverse recursively inorder a binary tree.
void destroyRec(Node *&root) noexcept
Free all the memory occupied by the tree root
void forest_preorder_traversal(Node *root, void(*visitFct)(Node *, int, int))
Preorder traversal of a forest.
size_t computeHeightRec(Node *root) noexcept
Compute the height of root
Main namespace for Aleph-w library functions.
bool areEquivalents(Node *t1, Node *t2, Equal &op) noexcept
Return true if trees are equivalents.
static void prefix(Node *root, DynList< Node * > &acc)
Utility functions for binary tree operations.
General tree (n-ary tree) node.