164# include <tclap/CmdLine.h>
170using namespace Aleph;
176 cout << node->get_key() <<
" ";
194 TCLAP::CmdLine
cmd(
"Generate forest from random binary tree",
' ',
"1.0");
196 TCLAP::ValueArg<int>
nArg(
"n",
"nodes",
197 "Number of nodes in the tree",
201 TCLAP::ValueArg<unsigned int>
seedArg(
"s",
"seed",
202 "Random seed (0 = use time)",
203 false, 0,
"unsigned int");
206 TCLAP::ValueArg<string>
outputArg(
"o",
"output",
208 false,
"arborescencia.Tree",
"string");
213 int n =
nArg.getValue();
214 unsigned int t =
seedArg.getValue();
222 cout <<
"Forest Generation Example" <<
endl;
223 cout <<
"=========================" <<
endl;
224 cout <<
"Parameters: n=" << n <<
", seed=" << t <<
endl;
231 cout <<
"Inserting " << n <<
" random values into BST..." <<
endl;
235 for (
int i = 0; i < n; i++)
239 value =
static_cast<int>(10.0 * n *
rand() / (
RAND_MAX + 1.0));
240 node = tree.
search(value);
242 while (node !=
nullptr);
252 cout <<
"BST verification: PASSED" <<
endl <<
endl;
254 cout <<
"Preorder traversal: ";
275 catch (TCLAP::ArgException &e)
277 cerr <<
"Error: " << e.error() <<
" for arg " << e.argId() <<
endl;
Node *& getRoot() noexcept
Return the root of tree.
Node * insert(Node *p) noexcept
Insert a node in the tree.
Node * search(const Key &key) const noexcept
Search a key.
T & get_key() noexcept
Returns a modifiable reference to the node contents.
static void printNode(BinTreeVtl< int >::Node *node, int, int)
Tree visualization and output generation.
__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 destroy_tree(Node *root)
Destroys (frees memory) the tree whose root is root.
void destroyRec(Node *&root) noexcept
Free recursively all the memory occupied by the tree 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.
std::string to_string(const time_t t, const std::string &format)
Format a time_t value into a string using format.
Binary search tree with nodes with virtual destructors,.
Functor to convert tree node to string for output.
string operator()(Tree_Node< int > *p)
Generic unbalanced binary search tree.
General tree (n-ary tree) node.