213# include <tclap/CmdLine.h>
218using namespace Aleph;
235 output1 << p->get_key() <<
" ";
240 output2 << p->get_key() <<
" ";
248 "Demonstrate BST join operation.\n"
249 "Creates two BSTs and joins them into one, generating visualization files.",
252 TCLAP::ValueArg<int>
nArg(
"n",
"count",
253 "Number of elements per tree (total = 2n)",
257 TCLAP::ValueArg<unsigned int>
seedArg(
"s",
"seed",
258 "Random seed (0 = use time)",
259 false, 0,
"unsigned int");
264 int n =
nArg.getValue();
265 unsigned int t =
seedArg.getValue();
272 cout <<
"=== BST Join Operation Demo ===" <<
endl;
273 cout <<
"Elements per tree: " << n <<
", Seed: " << t <<
endl <<
endl;
276 output.open(
"join-aux.Tree", ios::out);
277 output1.open(
"join-1-aux.Tree", ios::out);
278 output2.open(
"join-2-aux.Tree", ios::out);
282 cerr <<
"Error: cannot open output files" <<
endl;
290 cout <<
"Building first tree with " << n <<
" elements..." <<
endl;
291 for (
int i = 0; i < n; i++)
295 value =
rand() % (n * 100) + 1;
307 cout <<
" Nodes: " << n1
313 cout <<
"Building second tree with " << n <<
" elements..." <<
endl;
314 for (
int i = 0; i < n; i++)
318 value =
rand() % (n * 100) + 1;
331 cout <<
" Nodes: " << n2
341 cout <<
"Warning: duplicates found (unexpected)" <<
endl;
359 cout <<
" - join-1-aux.Tree (first tree)" <<
endl;
360 cout <<
" - join-2-aux.Tree (second tree)" <<
endl;
361 cout <<
" - join-aux.Tree (joined result)" <<
endl;
363 catch (TCLAP::ArgException& e)
365 cerr <<
"Error: " << e.error() <<
" for arg " << e.argId() <<
endl;
Core header for the Aleph-w library.
WeightedDigraph::Node Node
Node for binary search tree.
static BinNode *const NullPtr
__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.
bool check_bst(Node *p, const Compare &cmp=Compare())
Return true if p is a binary search tree.
Node * insert_in_bst(Node *&r, Node *p, const Compare &cmp=Compare()) noexcept
Insert a node p in a binary search tree.
void destroyRec(Node *&root) noexcept
Free recursively all the memory occupied by the tree root
Node * searchInBinTree(Node *root, const typename Node::key_type &key, const Compare &cmp=Compare()) noexcept
Search a key in a binary search tree.
Node * insert_root(Node *&root, Node *p, const Compare &cmp=Compare()) noexcept
Insert the node p as root of a binary search tree.
size_t computeHeightRec(Node *root) noexcept
Compute recursively the height of root
Main namespace for Aleph-w library functions.
std::ostream & join(const C &c, const std::string &sep, std::ostream &out)
Join elements of an Aleph-style container into a stream.
DynList< T > maps(const C &c, Op op)
Classic map operation.
Utility functions for binary tree operations.
Extended binary node with subtree count.
void print_key(Node *p, int, int)
void print_key1(Node *p, int, int)
void print_key2(Node *p, int, int)