45 cout <<
KEY(p) <<
" " ;
51 cout <<
KEY(p) <<
" " ;
55int main(
int argc,
char * argv[])
60 try { n = stoi(argv[1]); }
61 catch (...) { n = 1000; }
66 cerr <<
"Error: n must be a positive integer." << endl;
70 unsigned int seed = 0;
73 try {
seed =
static_cast<unsigned int>(stoul(argv[2])); }
74 catch (...) {
seed = 0; }
79 cout <<
"test_Splay_Tree " << n <<
" " <<
seed << endl;
86 cout <<
"Testing for insertions" << endl;
88 for (
int i = 0; i < n; i++)
104 cout << endl <<
"Inorder " << endl;
107 cout << endl <<
"Preorder " << endl;
110 cout << endl << endl;
112 cout <<
"Testing for random searches" << endl;
113 for (
int i = 0; i < n; ++i)
116 int value = values(idx);
117 cout <<
value <<
" ";
119 AH_ERROR(
"BUG detected ins searching");
121 cout <<
"Done" << endl;
123 cout <<
"Removing test" << endl;
125 for (
int i = 0; i < n/7; i++)
129 cout <<
value <<
" ";
131 assert(
value == p->get_key());
136 cout << endl <<
"Inorder " << endl << endl;
143 DynList<int>({122, 363, 1247, 510, 701, 1565, 1157, 728, 1564, 492, 861, 422}).
148 cout << endl <<
"Preorder " << endl;
The random number generators of Aleph: the one that gives the numbers of the gsl_rng_mt19937 of GSL,...
#define AH_ERROR(...)
Print an error message (always enabled).
size_t size_t int32_t value
Set-like container backed by a dynamic array.
size_t size() const noexcept
Return the current dimension of array.
T & append()
Allocate a new entry to the end of array.
void remove(T &item)
Given a valid reference to an item in the array, it removes it and decrease the dimension.
Doubly-linked list (defined in tpl_dynList.H).
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).
Node *& getRoot() noexcept
Get the top-down splay tree's root.
Node * remove(const Key &key) noexcept
Remove a key from a top down splay tree.
Node * insert(Node *p) noexcept
Inserts a node in a top-down splay tree.
Node * search(const Key &key) noexcept
Searches a key in a top-down splay tree.
int preOrderRec(Node *root, void(*visitFct)(Node *, int, int))
Traverse recursively in preorder a binary tree.
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
Operation for_each(Itor beg, const Itor &end, Operation op)
Apply an operation to each element in a range.
void print_node(Splay_Tree< int >::Node *p, int, int)
void write_node(Splay_Tree< int >::Node *p, int, int)
Top-down splay tree implementation (without rank support).