53 cout << node->get_key() <<
" ";
74 cout <<
"(" << idx <<
":" << p->
get_key() <<
")";
83int main(
int argc,
char *argv[])
85 int n = argc > 1 ? stoi(argv[1]) : 1000;
87 unsigned int t = std::time(0);
94 cout << argv[0] <<
" " << n <<
" " << t << endl;
103 cerr <<
"Error: n must be <= 1000 to avoid infinite loops with current RNG range." << endl;
107 cout <<
"Inserting " << n <<
" random values in tree ...\n";
109 for (
int i = 0; i < n; i++)
118 while (node not_eq
nullptr);
124 cout <<
value <<
" ";
126 cout << endl << endl;
132 if (ttree ==
nullptr)
134 cout <<
"Warning: Empty tree, no forest to process." << endl;
138 generate_forest<Tree_Node<int>,
Write> (ttree, std::cout);
140 cout << endl <<
"Secuencia paréntesis: ";
143 while (rc !=
nullptr)
146 rc = rc->get_right_sibling();
148 cout << endl << endl;
150 cout <<
"Secuencia en notación Deway: ";
154 while (rc !=
nullptr)
159 rc = rc->get_right_sibling();
166 cout << endl << ins_count <<
" insertions" << endl
167 <<
"prefijo: " << endl;
169 cout << endl << endl;
171 cout <<
"sufijo: " << endl;
173 cout << endl << endl;
175 cout <<
"infijo: " << endl;
177 cout << endl << endl;
183 cout <<
"IPL = " << ipl << endl
184 <<
"EPL = " << ipl + 2*n << endl;
199 cout <<
"Removing " << n/4 <<
" keys" << endl;
201 std::vector<int>
keys;
202 Aleph::for_each_in_order<BinTree<int>::Node>(tree.
getRoot(), [&
keys](
auto node) {
203 keys.push_back(node->get_key());
205 std::shuffle(
keys.begin(),
keys.end(), std::mt19937(t));
207 for (
size_t i = 0; i < (size_t)(n/4) && i <
keys.size(); i++)
214 cout << node->get_key() <<
" ";
219 cout << endl << del_count <<
" deletions" << endl
231 cout << argv[0] <<
" " << n <<
" " << t << endl;
The random number generators of Aleph: the one that gives the numbers of the gsl_rng_mt19937 of GSL,...
Core header for the Aleph-w library.
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 * remove(const Key &key) noexcept(nothrow_compare_copy_v< Compare, Key >)
Remove a key from the tree.
Node * search(const Key &key) const noexcept(nothrow_compare_copy_v< Compare, Key >)
Search a key.
bool verifyBin() const
See verify().
A random number generator with the sequences of GSL's gsl_rng_mt19937.
Forward declaration used by CRTP helpers before the full node definition.
Tree_Node * get_right_sibling() const noexcept
Returns the right sibling of this.
void for_each_child(Operation &op) const
Visits each child of this and executes the operation on the child node.
T & get_key() noexcept
Returns a modifiable reference to the node contents.
Tree visualization and output generation.
int postOrderRec(Node *root, void(*visitFct)(Node *, int, int))
Traverse recursively in postorder a binary tree.
int preOrderRec(Node *root, void(*visitFct)(Node *, int, int))
Traverse recursively in preorder a binary tree.
Node * copyRec(Node *root)
Copy a tree.
size_t internal_path_length(Node *p) noexcept
Compute the internal path length.
void destroy_forest(Node *root)
Destroys (frees memory) the forest whose first tree is root.
int inOrderRec(Node *root, void(*visitFct)(Node *, int, int))
Traverse recursively inorder a binary tree.
void destroyRec(Node *&root) noexcept
Free all the memory occupied by the tree root
void split_key(Node *&root, const Key &key, Node *&l, Node *&r, const Compare &cmp=Compare()) noexcept
Split a binary search tree according to a key.
Main namespace for Aleph-w library functions.
std::string code(Node *root)
Compute a string with the Lukasiewicz`s word of a tree.
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 without virtual destructors,.
string operator()(Tree_Node< int > *p)
void print_forest_par(Tree_Node< int > *p)
void print_forest_deway(Tree_Node< int > *p, const string &idx)
static void printNode(BinTree< int >::Node *node, int, int)
Generic unbalanced binary search tree.
General tree (n-ary tree) node.