99#include <tclap/CmdLine.h>
108using namespace Aleph;
125 cout <<
"Node " <<
prefix[i++];
128 cout <<
"." <<
prefix[i++];
132 if (
static_cast<size_t>(len) >=
dim)
152 const size_t dim = 10 *
h;
168 cout <<
" " << node->get_key();
178 const int rd = 1 +
static_cast<int>(1.0 * n *
rand() / (
RAND_MAX + 1.0));
202 TCLAP::CmdLine
cmd(
"Deway numbering example for trees",
' ',
"1.0");
204 TCLAP::ValueArg<int>
nArg(
"n",
"nodes",
"Number of nodes in the tree",
false, 10,
"int");
207 TCLAP::ValueArg<unsigned int>
seedArg(
"s",
"seed",
"Random seed (0 = use time)",
false, 0,
213 int n =
nArg.getValue();
214 unsigned int t =
seedArg.getValue();
221 cout <<
"Deway Numbering Example" <<
endl;
222 cout <<
"=======================" <<
endl;
223 cout <<
"Parameters: n=" << n <<
", seed=" << t <<
endl <<
endl;
228 cout <<
"Binary tree (preorder):";
232 cout <<
"Binary tree (inorder):";
239 cout <<
"Forest (preorder):";
243 cout <<
"Forest (postorder):";
250 cout <<
"Conversion verification: PASSED" <<
endl <<
endl;
253 cout <<
"Deway Numbering:" <<
endl;
254 cout <<
"----------------" <<
endl;
264 catch (TCLAP::ArgException &e)
266 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)
size_t blossom_maximum_cardinality_matching(const GT &g, DynDlist< typename GT::Arc * > &matching, SA sa=SA())
Alias of compute_maximum_cardinality_general_matching().
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 recursively 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 recursively the height of root
Main namespace for Aleph-w library functions.
static void prefix(Node *root, DynList< Node * > &acc)
bool areEquivalents(Node *t1, Node *t2, Equal &op) noexcept
Return true if trees are equivalents.
Utility functions for binary tree operations.
General tree (n-ary tree) node.