164# include <tclap/CmdLine.h>
170using namespace Aleph;
176 cout << node->get_key() <<
" ";
190int main(
int argc,
char *argv[])
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");
211 cmd.parse(argc, argv);
213 int n = nArg.getValue();
214 unsigned int t = seedArg.getValue();
215 string outputFile = outputArg.getValue();
222 cout <<
"Forest Generation Example" << endl;
223 cout <<
"=========================" << endl;
224 cout <<
"Parameters: n=" << n <<
", seed=" << t << endl;
225 cout <<
"Output file: " << outputFile << endl << 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));
242 while (node !=
nullptr);
249 cout << ins_count <<
" insertions completed" << endl;
252 cout <<
"BST verification: PASSED" << endl << endl;
254 cout <<
"Preorder traversal: ";
256 cout << endl << endl;
263 ofstream
output(outputFile, ios::trunc);
267 cout <<
"Forest written to " << outputFile << endl;
273 cout << endl <<
"Done." << endl;
275 catch (TCLAP::ArgException &e)
277 cerr <<
"Error: " << e.error() <<
" for arg " << e.argId() << endl;
size_t size_t int32_t value
Node * insert(Node *p) noexcept(nothrow_compare_copy_v< Compare, Key >)
Insert a node in the tree.
Node *& getRoot() noexcept
Return the root of tree.
Node * search(const Key &key) const noexcept(nothrow_compare_copy_v< Compare, Key >)
Search a key.
bool verifyBin() const
See verify().
Forward declaration used by CRTP helpers before the full node definition.
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 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.
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.