I looking for method which can give me the height difference of an AVL_tree.
The method i come up with up now is this.
1 2 3 4 5 6 7 8 9 10 11
int avl_tree::balance(node* pointer)
{
while (pointer->left != NULL) {
int left = balance(pointer ->left);
}
while (pointer->right != NULL) {
int right = balance(pointer->right);
}
return left - right;
}
Which recursively calls itself, but the problem is that i get stuck on the first line..
Note that balancing avl tree is not something you do AFTER you have inserted elements into the tree. There is a reason why avl trees are very tightly balanced and it is because of the rigorous work that goes into keeping them balanced. As you will see from the code I have, the tree is balanced pretty much after every other insertion (difference between height of left and right has to be 1 or less)