41# include <gsl/gsl_rng.h>
55 cout << node->get_key() <<
" ";
76 cout <<
"(" << idx <<
":" << p->
get_key() <<
")";
89 unsigned int t = std::time(0);
97 cout <<
argv[0] <<
" " << n <<
" " << t <<
endl;
106 cerr <<
"Error: n must be <= 1000 to avoid infinite loops with current RNG range." <<
endl;
110 cout <<
"Inserting " << n <<
" random values in tree ...\n";
112 for (
int i = 0; i < n; i++)
119 node = tree.
search(value);
121 while (node
not_eq nullptr);
127 cout << value <<
" ";
135 if (
ttree ==
nullptr)
137 cout <<
"Warning: Empty tree, no forest to process." <<
endl;
143 cout <<
endl <<
"Secuencia paréntesis: ";
145 auto rc =
ttree->get_right_sibling();
146 while (
rc !=
nullptr)
149 rc =
rc->get_right_sibling();
153 cout <<
"Secuencia en notación Deway: ";
155 rc =
ttree->get_right_sibling();
157 while (
rc !=
nullptr)
162 rc =
rc->get_right_sibling();
170 <<
"prefijo: " <<
endl;
174 cout <<
"sufijo: " <<
endl;
178 cout <<
"infijo: " <<
endl;
186 cout <<
"IPL = " <<
ipl <<
endl
187 <<
"EPL = " <<
ipl + 2*n <<
endl;
202 cout <<
"Removing " << n/4 <<
" keys" <<
endl;
204 std::vector<int>
keys;
206 keys.push_back(node->get_key());
208 std::shuffle(
keys.begin(),
keys.end(), std::mt19937(t));
210 for (
size_t i = 0; i < (size_t)(n/4) && i <
keys.size(); i++)
217 cout << node->get_key() <<
" ";
234 cout <<
argv[0] <<
" " << n <<
" " << t <<
endl;
Core header for the Aleph-w library.
Node *& getRoot() noexcept
Return the root of tree.
Node * insert(Node *p) noexcept
Insert a node in the tree.
Node * search(const Key &key) const noexcept
Search a key.
Node * remove(const Key &key) noexcept
Remove a key from the tree.
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 recursively 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 recursively 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.
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.
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,.
void operator()(gsl_rng *r) const
string operator()(Tree_Node< int > *p)
std::unique_ptr< gsl_rng, GslRngDeleter > GslRngHandle
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.