118# include <tclap/CmdLine.h>
125using namespace Aleph;
139 output << p->getCount() <<
" ";
144 output <<
"tag " << pos <<
" " << pos <<
" N -15 35" <<
endl;
152 "Demonstrate ranked BST with subtree counts.\n"
153 "Creates a tree where each node stores the size of its subtree.",
156 TCLAP::ValueArg<int>
nArg(
"n",
"count",
157 "Number of elements",
161 TCLAP::ValueArg<unsigned int>
seedArg(
"s",
"seed",
162 "Random seed (0 = use time)",
163 false, 0,
"unsigned int");
168 int n =
nArg.getValue();
169 unsigned int t =
seedArg.getValue();
176 cout <<
"=== Ranked BST Demo ===" <<
endl;
177 cout <<
"Elements: " << n <<
", Seed: " << t <<
endl <<
endl;
180 output.open(
"rank-tree-aux.Tree", ios::out);
183 cerr <<
"Error: cannot open output file" <<
endl;
190 cout <<
"Building ranked BST..." <<
endl;
192 for (
int i = 0; i < n; i++)
197 value =
static_cast<int>(10.0 * n *
rand() / (
RAND_MAX + 1.0));
204 cout << value <<
" ";
220 for (
int i = 0; i <
min(n, 5); i++)
241 cout <<
" - rank-tree-aux.Tree (with subtree counts and position tags)" <<
endl;
245 catch (TCLAP::ArgException& e)
247 cerr <<
"Error: " << e.error() <<
" for arg " << e.argId() <<
endl;
Core header for the Aleph-w library.
WeightedDigraph::Node Node
Node for extended binary search tree.
static BinNodeXt *const NullPtr
__gmp_expr< typename __gmp_resolve_expr< T, V >::value_type, __gmp_binary_expr< __gmp_expr< T, U >, __gmp_expr< V, W >, __gmp_min_function > > min(const __gmp_expr< T, U > &expr1, const __gmp_expr< V, W > &expr2)
__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.
Node * insert_by_key_xt(Node *&r, Node *p, Compare &cmp) noexcept
Insert a node in an extended binary search tree.
bool check_rank_tree(Node *root) noexcept
Return true if root is a valid extended binary tree.
bool check_bst(Node *p, const Compare &cmp=Compare())
Return true if p is a binary search tree.
int inOrderRec(Node *root, void(*visitFct)(Node *, int, int))
Traverse recursively inorder a binary tree.
Node * select(Node *r, const size_t pos)
Iterative selection of a node according to inorder position.
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.
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.
Extended binary node with subtree count.
Generic unbalanced binary search tree.
Lazy and scalable dynamic array implementation.
void print_tag(Node *, int, int pos)
void print_key(Node *p, int, int)
void print_count(Node *p, int, int)