100# include <tclap/CmdLine.h>
111using namespace Aleph;
129 cout <<
"Node " <<
prefix[i++];
132 cout <<
"." <<
prefix[i++];
136 if (
static_cast<size_t>(len) >=
dim)
156 const size_t dim = 10 *
h;
172 cout <<
" " << node->get_key();
182 const int rd = 1 +
static_cast<int>(1.0 * n *
rand() / (
RAND_MAX + 1.0));
206 TCLAP::CmdLine
cmd(
"Deway numbering example for trees",
' ',
"1.0");
208 TCLAP::ValueArg<int>
nArg(
"n",
"nodes",
209 "Number of nodes in the tree",
213 TCLAP::ValueArg<unsigned int>
seedArg(
"s",
"seed",
214 "Random seed (0 = use time)",
215 false, 0,
"unsigned int");
220 int n =
nArg.getValue();
221 unsigned int t =
seedArg.getValue();
228 cout <<
"Deway Numbering Example" <<
endl;
229 cout <<
"=======================" <<
endl;
230 cout <<
"Parameters: n=" << n <<
", seed=" << t <<
endl <<
endl;
235 cout <<
"Binary tree (preorder):";
239 cout <<
"Binary tree (inorder):";
250 t->set_is_root(
true);
252 cout <<
"Forest (preorder):";
256 cout <<
"Forest (postorder):";
263 cout <<
"Conversion verification: PASSED" <<
endl <<
endl;
266 cout <<
"Deway Numbering:" <<
endl;
267 cout <<
"----------------" <<
endl;
277 catch (TCLAP::ArgException &e)
279 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.
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.
Divide_Conquer_DP_Result< Cost > divide_and_conquer_partition_dp(const size_t groups, const size_t n, Transition_Cost_Fn transition_cost, const Cost inf=dp_optimization_detail::default_inf< Cost >())
Optimize partition DP using divide-and-conquer optimization.
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.