49 cout << node->get_key() <<
" ";
52int main(
int argc,
char *argv[])
57 try { n = stoi(argv[1]); }
catch (...) { n = 10; }
62 cerr <<
"n must be positive" << endl;
66 unsigned int seed = 0;
69 try {
seed = stoul(argv[2]); }
catch (...) {
seed = 0; }
75 cout << argv[0] <<
" " << n <<
" " <<
seed << endl;
81 cout <<
"Inserting " << n <<
" random values in tree ...\n";
83 for (
int i = 0; i < n; i++)
92 while (node not_eq NULL);
100 cout << endl << endl;
104 cout <<
"Sorting keys array" << endl;
106 for (
int i = 0; i <
keys.size(); ++i)
107 cout <<
keys(i) <<
" ";
109 <<
"done" << endl << endl;
111 cout <<
"inorden traversal prio" << endl;
113 cout << endl << endl;
115 cout <<
"Testing select" << endl;
117 for (
int i = 0; i < n; i++)
120 cout << node->get_key() <<
" ";
121 assert(node->get_key() ==
keys(i));
124 cout <<
"done!" << endl << endl;
128 cout <<
"testing random positions" << endl;
129 for (
int i = 0; i < n; ++i)
132 std::pair<int, Splay_Tree_Rk<int>::Node*> pos =
135 assert(pos.second != NULL);
136 assert(pos.second->get_key() ==
keys(idx));
137 assert(idx == pos.first);
138 cout << idx <<
"<-->" << pos.first << endl
139 <<
keys(idx) <<
"<-->" << pos.second->get_key() <<
" " << endl;
142 for (
int i = 0; i < n/2; i++)
146 cout <<
value <<
" ";
148 assert(node != NULL);
149 assert(node->get_key() ==
value);
154 cout << endl <<
"verifying Splay_Rk after deletions ... "
157 cout <<
" done" << endl;
159 cout <<
"Inorden" << endl;
170 cout << endl << argv[0] <<
" " << n <<
" " <<
seed << 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
Set-like container backed by a dynamic array.
void reserve(const size_t l, const size_t r)
Allocate a range of entries.
A random number generator with the sequences of GSL's gsl_rng_mt19937.
static constexpr result_type max() noexcept
The greatest number of operator()(): 2^32 - 1.
unsigned long uniform_int(const unsigned long n)
An integer in [0, n), each with the same probability, as gsl_rng_uniform_int(r, n).
std::pair< long, Node * > position(const Key &key)
Returns the inorder (sorted) position of key.
Node * insert(Node *p)
Inserts a node in a top down splay tree.
Node * remove(const Key &key)
Remove a key from a top-down splay tree.
Node * search(const Key &key)
Searches a key in a top down splay tree.
Node * select(const size_t &i)
Returns the node whose inorder position in the extended tree is i.
Node *& getRoot()
Get the top-down splay tree's root.
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.
void quicksort(T *a, const long l, const long r, const Compare &cmp=Compare())
Sort an array using iterative quicksort with optimizations.
void printNode(Splay_Tree_Rk< int >::Node *node, int, int)
Utility functions for binary tree operations.
Comprehensive sorting algorithms and search utilities for Aleph-w.
Top-down splay tree with rank support.