207# include <tclap/CmdLine.h>
217using namespace Aleph;
231 "Demonstrate root insertion in BST.\n"
232 "Shows how root insertion maintains recently inserted elements near the root.",
235 TCLAP::ValueArg<int>
nArg(
"n",
"count",
236 "Number of elements",
240 TCLAP::ValueArg<unsigned int>
seedArg(
"s",
"seed",
241 "Random seed (0 = use time)",
242 false, 0,
"unsigned int");
247 int n =
nArg.getValue();
248 unsigned int t =
seedArg.getValue();
255 cout <<
"=== Root Insertion Demo ===" <<
endl;
256 cout <<
"Elements: " << n <<
", Seed: " << t <<
endl <<
endl;
259 output.open(
"insert_root-aux.Tree", ios::out);
262 cerr <<
"Error: cannot open output file" <<
endl;
270 cout <<
"Inserting values: ";
271 for (
int i = 0; i < n; i++)
273 int value =
static_cast<int>(10.0 * n *
rand() / (
RAND_MAX + 1.0));
283 cout <<
KEY(p) <<
" ";
291 cout <<
"Statistics:" <<
endl;
298 cout <<
" [OK] Root is the last inserted element" <<
endl;
300 cout <<
" [Note] Root may have changed due to rotations" <<
endl;
307 cout <<
endl <<
"Generated file:" <<
endl;
308 cout <<
" - insert_root-aux.Tree" <<
endl;
312 catch (TCLAP::ArgException& e)
314 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.
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.
Utility functions for binary tree operations.
Basic binary tree node definitions.
static void printNode(BinNode< int > *node, int, int)