55 unsigned long r = 1+ (int) (1000.0*rand()/(RAND_MAX+1.0));
70 <<
"Secuencia aleatorios: ";
81 cout << node->get_key() <<
" ";
86 cout << node->get_key() <<
" ";
91 cout << node->getPriority() <<
" ";
96 cout <<
"(" << node->get_key() <<
"," << node->getPriority() <<
") ";
99int main(
int argc,
char *argv[])
102 unsigned int t = std::time(0);
108 n = std::stoi(argv[1]);
111 t = std::stoi(argv[2]);
120 cout <<
"n must be positive" << endl;
126 cout <<
"testTreapRec " << n <<
" " << t << endl;
132 cout <<
"Inserting " << n <<
" random values in treee ...\n";
134 for (i = 0; i < n; i++)
138 value = (int) (10.0*n*rand()/(RAND_MAX+1.0));
141 while (node not_eq NULL);
145 cout <<
"(" <<
value <<
"," <<
PRIO(node) <<
") ";
149 <<
"level order" << endl;
153 cout << p->get_key() <<
" ";
160 <<
"Preorden" << endl;
164 cout << endl << endl;
166 cout <<
"inorden prio" << endl;
168 cout << endl << endl;
172 cout << endl << endl;
176 <<
"Preorden prio" << endl;
180 cout << endl << endl;
182 cout <<
"inorden prio" << endl;
184 cout << endl << endl;
188 cout << endl << endl;
190 for (i = 0; i < n/2; i++)
194 value = (int) (10.0*n*rand()/(RAND_MAX+1.0));
197 while (node == NULL);
199 cout <<
value <<
" ";
203 cout << endl <<
"verifying Treap after deletions ... "
206 cout <<
" done" << endl;
208 cout <<
"Preorden" << endl;
212 cout <<
"inorden prio" << endl;
221 cout << endl <<
"testTreapRec " << 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 * search(const Key &key) const noexcept(nothrow_compare_v< Compare, Key >)
Search a key in a treap.
Node * insert(Node *root, Node *p) noexcept(nothrow_compare_v< Compare, Key >)
Node * remove(const Key &key) noexcept(nothrow_compare_v< Compare, Key >)
Remove a key from the tree.
int preOrderRec(Node *root, void(*visitFct)(Node *, int, int))
Traverse recursively in preorder a binary tree.
bool level_traverse(Node *root, Operation &operation)
Level traverse a tree and execute an operation.
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
unsigned long & PRIO(Node *p) noexcept
Access the priority of a treap node.
Main namespace for Aleph-w library functions.
bool is_treap(Node *root) noexcept
Validate that a tree satisfies treap (heap) property.
long sequential_search(T *a, const T &x, const long l, const long r, Equal eq=Equal())
Linear search for an element in an array.
Treap (a special type of randomized binary search tree) using nodes without virtual destructor.
void printPair(Treap< int >::Node *node, int, int)
void printPrio(Treap< int >::Node *node, int, int)
void print_aleatorio_and_reset_dynarray()
DynArray< unsigned long > rand_sequence
void printNode(Treap< int >::Node *node, int, int)
Utility functions for binary tree operations.
Lazy and scalable dynamic array implementation.
Comprehensive sorting algorithms and search utilities for Aleph-w.
Treap: randomized BST combining tree and heap properties.