46main (
int argc,
char *argv[])
51 char *endptr =
nullptr;
53 const long parsed_n = strtol (argv[1], &endptr, 10);
54 if (errno != 0 or endptr == argv[1] or *endptr !=
'\0' or
55 parsed_n <= 0 or parsed_n > 1000000)
57 cerr <<
"Invalid value for n: " << argv[1] <<
" (must be between 1 and 1,000,000)" << endl;
60 n =
static_cast<int>(parsed_n);
63 auto t =
static_cast<unsigned int> (time (
nullptr));
66 if (argv[2][0] ==
'-')
68 cerr <<
"Invalid value for t (must be non-negative): " << argv[2] << endl;
71 char *endptr =
nullptr;
73 const unsigned long parsed_t = strtoul (argv[2], &endptr, 10);
74 if (errno != 0 or endptr == argv[2] or *endptr !=
'\0' or parsed_t > UINT_MAX)
76 cerr <<
"Invalid value for t: " << argv[2] << endl;
79 t =
static_cast<unsigned int>(parsed_t);
85 const uint64_t upper_64 =
static_cast<uint64_t
>(n) * 100;
86 const int upper = (upper_64 >
static_cast<uint64_t
>(INT_MAX)) ?
87 INT_MAX :
static_cast<int>(upper_64);
88 std::uniform_int_distribution<int> dist(1, upper);
90 cout <<
"testSplayTree " << n <<
" " << t << endl;
94 cout <<
"Inserting " << n <<
" random values in tree ...\n";
96 unsigned int insCount = 0;
98 while (insCount <
static_cast<unsigned int>(n))
109 cout << insCount <<
" Items inserted" << endl;
112 cout <<
"arbol equilibrado" << endl;
115 cout <<
"error de equilibrio en el arbol" << endl;
121 cout <<
"testSplayTree " << n <<
" " << t << endl;
size_t size_t int32_t value
Node * insert(Node *p)
Inserts a node in a top down splay tree.
Node * search(const Key &key)
Searches a key in a top down splay tree.
Node *& getRoot()
Get the top-down splay tree's root.
void destroyRec(Node *&root) noexcept
Free all the memory occupied by the tree root
void exit(const char *file, int line, const char *format,...)
Print a message and exit the program.
Extended binary node with subtree count.
Top-down splay tree with rank support.