100# include <tclap/CmdLine.h>
107using namespace Aleph;
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",
205 "Number of nodes in the tree",
209 TCLAP::ValueArg<unsigned int>
seedArg(
"s",
"seed",
210 "Random seed (0 = use time)",
211 false, 0,
"unsigned int");
216 int n =
nArg.getValue();
217 unsigned int t =
seedArg.getValue();
224 cout <<
"Deway Numbering Example" <<
endl;
225 cout <<
"=======================" <<
endl;
226 cout <<
"Parameters: n=" << n <<
", seed=" << t <<
endl <<
endl;
231 cout <<
"Binary tree (preorder):";
235 cout <<
"Binary tree (inorder):";
246 t->set_is_root(
true);
248 cout <<
"Forest (preorder):";
252 cout <<
"Forest (postorder):";
259 cout <<
"Conversion verification: PASSED" <<
endl <<
endl;
273 catch (TCLAP::ArgException &e)
275 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.
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.
constexpr Node *& RLINK(Node *p) noexcept
Return the right tree of p.
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.
constexpr Node *& LLINK(Node *p) noexcept
Return a pointer to left subtree.
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.
DynList< T > maps(const C &c, Op op)
Classic map operation.
Utility functions for binary tree operations.
General tree (n-ary tree) node.