50 cout << node->get_key() <<
" ";
55 cout << node->getPriority() <<
" ";
59int main(
int argc,
char *argv[])
64 try { n = stoi(argv[1]); }
catch (...) { n = 10; }
69 cerr <<
"n must be positive" << endl;
73 unsigned int t = std::time(0);
76 try { t = stoul(argv[2]); }
catch (...) { t = std::time(0); }
81 cout <<
"testTreap_Rk " << n <<
" " << t << endl;
88 cout <<
"Inserting " << n <<
" random values in tree ...\n";
90 for (i = 0; i < n; i++)
94 value = (int) (10.0*n*rand()/(RAND_MAX+1.0));
97 while (node not_eq NULL);
110 <<
"Preorden" << endl;
114 cout << endl << endl;
116 cout <<
"inorden prio" << endl;
118 cout << endl << endl;
120 for (i = 0; i < n; i++)
123 cout << node->get_key() <<
" ";
126 cout << endl << endl;
128 cout <<
"Lista de posiciones infijas" << endl;
130 for (i = 0; i < n; ++i)
132 std::pair<int,Treap_Rk<int>::Node*> pos = tree.
position(
keys[i]);
133 cout <<
keys[i] <<
"<-->" << pos.first << endl;
136 cout << endl << endl;
138 for (i = 0; i < n/2; i++)
142 assert(node != NULL);
144 cout <<
value <<
" ";
148 cout << endl <<
"verifying Treap_Rk after deletions ... "
152 cout <<
" done" << endl;
154 cout <<
"Preorden" << endl;
158 cout <<
"inorden prio" << endl;
165 cout <<
"Recorrido por iterador" << endl;
167 cout <<
KEY(it.get_curr()) <<
" ";
173 cout <<
"Eliminacion de rango [" << beg <<
" .. " << end <<
"]" << endl;
183 cout <<
"Arbol restante" << endl;
187 cout <<
"Arbol eliminado" << endl;
194 cout << endl <<
"testTreap_Rk " << n <<
" " << t << endl;
Core header for the Aleph-w library.
size_t size_t int32_t value
Node *& getRoot() noexcept
Return the tree's root.
Node * select(const size_t i) const
Return the i-th node in order sense.
size_t size() const noexcept
Return the number of nodes contained in the tree.
bool insert(Node *&root, Node *p) noexcept(nothrow_compare_v< Compare, Key >)
Node * search(const Key &key) const noexcept(nothrow_compare_v< Compare, Key >)
Search a key in a treap.
Node * remove(Node *&root, const Key &key) noexcept(nothrow_compare_v< Compare, Key >)
std::pair< int, Node * > position(const Key &key) const noexcept(nothrow_compare_copy_v< Compare, Key >)
Compute the inorder position of a key.
int preOrderRec(Node *root, void(*visitFct)(Node *, int, int))
Traverse recursively in preorder a binary tree.
bool check_rank_tree(Node *root) noexcept
Return true if root is a valid extended binary tree.
size_t internal_path_length(Node *p) noexcept
Compute the internal path length.
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
Main namespace for Aleph-w library functions.
bool is_treap(Node *root) noexcept
Validate that a tree satisfies treap (heap) property.
Extended treap (a special type of randomized binary search tree) which manages selection and splittin...
void printNode(Treap_Rk< int >::Node *node, int, int)
void printPrio(Treap_Rk< int >::Node *node, int, int)
Utility functions for binary tree operations.
Lazy and scalable dynamic array implementation.
Treap with rank (order statistics).