164# include <tclap/CmdLine.h>
169using namespace Aleph;
174 cout << node->get_key() <<
" ";
192 TCLAP::CmdLine
cmd(
"Generate forest from random binary tree",
' ',
"1.0");
194 TCLAP::ValueArg<int>
nArg(
"n",
"nodes",
195 "Number of nodes in the tree",
199 TCLAP::ValueArg<unsigned int>
seedArg(
"s",
"seed",
200 "Random seed (0 = use time)",
201 false, 0,
"unsigned int");
204 TCLAP::ValueArg<string>
outputArg(
"o",
"output",
206 false,
"arborescencia.Tree",
"string");
211 int n =
nArg.getValue();
212 unsigned int t =
seedArg.getValue();
220 cout <<
"Forest Generation Example" <<
endl;
221 cout <<
"=========================" <<
endl;
222 cout <<
"Parameters: n=" << n <<
", seed=" << t <<
endl;
229 cout <<
"Inserting " << n <<
" random values into BST..." <<
endl;
233 for (
int i = 0; i < n; i++)
237 value =
static_cast<int>(10.0 * n *
rand() / (
RAND_MAX + 1.0));
238 node = tree.
search(value);
240 while (node !=
nullptr);
252 cout <<
"Preorder traversal: ";
273 catch (TCLAP::ArgException &e)
275 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.
std::string to_string(const time_t t, const std::string &format)
Format a time_t value into a string using format.
DynList< T > maps(const C &c, Op op)
Classic map operation.
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.