48 cout <<
"(" << p->get_key() <<
"," << (int) (p->getDiff()) <<
") ";
53 cout << p->get_key() <<
" ";
56int main(
int argc,
char *argv[])
59 unsigned int t = std::time(0);
76 cerr <<
"Error: n must be a positive integer." << endl;
94 cout <<
"testAvl " << n <<
" " << t << endl;
101 cout <<
"Inserting " << n <<
" random values in tree ...\n";
103 for (i = 0; i < n; i++)
107 value = (int) (n*10.0*rand()/(RAND_MAX+1.0));
110 while (node not_eq
nullptr);
112 cout <<
value <<
" ";
117 cout << endl <<
"verifying avl tree after insertions ... "
120 cout <<
" done" << endl;
122 cout <<
"start-prefix ";
124 cout << endl << endl;
129 cout << endl << endl;
132 for (i = 0; i < n/2; i++)
136 assert(node !=
nullptr);
138 cout <<
value <<
" ";
145 cout << endl << endl;
147 cout << endl <<
"verifying avl tree after deletions ... " ;
149 cout <<
" done" << endl;
Core header for the Aleph-w library.
bool is_avl(Node *p)
Validate that a tree satisfies AVL properties.
size_t size_t int32_t value
Node * insert(Node *p) noexcept(nothrow_compare_v< Compare, Key >)
Insert the node pointed by p in the tree.
Node * remove(const Key &key) noexcept(nothrow_compare_v< Compare, Key >)
Remove from an AVL tree the node containing key key.
constexpr Node *& getRoot() noexcept
Return a modifiable reference to tree's root.
Node * search(const Key &key) const noexcept(nothrow_compare_v< Compare, Key >)
Search a node containing key.
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
Main namespace for Aleph-w library functions.
AVL binary search tree with nodes without a virtual destructor.
static void print(Avl_Tree< int >::Node *p, int, int)
static void print_pair(Avl_Tree< int >::Node *p, int, int)
AVL tree implementation (height-balanced BST).
Utility functions for binary tree operations.