207# include <tclap/CmdLine.h>
213using namespace Aleph;
227 "Demonstrate root insertion in BST.\n"
228 "Shows how root insertion maintains recently inserted elements near the root.",
231 TCLAP::ValueArg<int>
nArg(
"n",
"count",
232 "Number of elements",
236 TCLAP::ValueArg<unsigned int>
seedArg(
"s",
"seed",
237 "Random seed (0 = use time)",
238 false, 0,
"unsigned int");
243 int n =
nArg.getValue();
244 unsigned int t =
seedArg.getValue();
251 cout <<
"=== Root Insertion Demo ===" <<
endl;
252 cout <<
"Elements: " << n <<
", Seed: " << t <<
endl <<
endl;
255 output.open(
"insert_root-aux.Tree", ios::out);
258 cerr <<
"Error: cannot open output file" <<
endl;
266 cout <<
"Inserting values: ";
267 for (
int i = 0; i < n; i++)
269 int value =
static_cast<int>(10.0 * n *
rand() / (
RAND_MAX + 1.0));
294 cout <<
" [OK] Root is the last inserted element" <<
endl;
296 cout <<
" [Note] Root may have changed due to rotations" <<
endl;
304 cout <<
" - insert_root-aux.Tree" <<
endl;
308 catch (TCLAP::ArgException& e)
310 cerr <<
"Error: " << e.error() <<
" for arg " << e.argId() <<
endl;
Core header for the Aleph-w library.
Node for binary search tree.
__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.
void destroyRec(Node *&root) noexcept
Free recursively all the memory occupied by the tree root
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.
DynList< T > maps(const C &c, Op op)
Classic map operation.
Utility functions for binary tree operations.
Basic binary tree node definitions.
static void printNode(BinNode< int > *node, int, int)