39 if (root ==
nullptr) {
42 return 1 + std::max(
height(root->left),
height(root->right));
68 node *t = root->right;
80 if (root->left ==
nullptr) {
93 if (root ==
nullptr) {
96 if (item < root->
data) {
97 root->left =
insert(root->left, item);
99 root->right =
insert(root->right, item);
123 if (root ==
nullptr) {
126 if (element < root->
data) {
128 }
else if (element > root->data) {
129 root->right =
deleteNode(root->right, element);
133 if (!root->right || !root->left) {
134 node *temp = !root->right ? root->left : root->right;
140 root->data = temp->data;
141 root->right =
deleteNode(root->right, temp->data);
164 std::queue<node *> q;
168 std::cout << root->data <<
" ";
185 node *root =
nullptr;
187 for (i = 1; i <= 7; i++) root =
insert(root, i);
188 std::cout <<
"LevelOrder: ";
191 std::cout <<
"\nLevelOrder: ";
194 std::cout <<
"\nLevelOrder: ";
node * insert(node *root, int item)
inserts a new element into AVL tree
node * leftRotate(node *root)
node * createNode(int data)
creates and returns a new node
node * minValue(node *root)
struct node { int data; int height; struct node *left; struct node *right;} node
for std::queue
void deleteAllNodes(const node *const root)
calls delete on every node
node * deleteNode(node *root, int element)
removes a given element from AVL tree
int getBalance(node *root)
node * rightRotate(node *root)
void levelOrder(node *root)
prints given tree in the LevelOrder