i have written a binary tree program that can insert, delete and display the avl tree. it works fine but when i delete and element the program does not proform a rotation and i dont know why.
{
if (tree == NULL) {
*ht_dec = FALSE;
return NULL;
}
switch (tree->balance)
{
case 0:
tree->balance = 1;
*ht_dec = FALSE;
break;
case -1:
tree->balance = 0;
break;
case 1:
if (tree->left != NULL && (tree->left->balance == 0 || tree->left->balance == 1))
{
struct node *leftChild = tree->left;
tree->left = leftChild->right;
leftChild->right = tree;
tree->balance = 0;
tree = leftChild;
*ht_dec = TRUE;
}
else if (tree->left != NULL && tree->left->right != NULL)
{
struct node *leftChild = tree->left;
struct node *rightGrandChild = leftChild->right;
leftChild->right = rightGrandChild->left;
rightGrandChild->left = leftChild;
tree->left = rightGrandChild->right;
rightGrandChild->right = tree;
if (rightGrandChild->balance == 1)
tree->balance = -1;
else
tree->balance = 0;
if (rightGrandChild->balance == -1)
leftChild->balance = 1;
else
leftChild->balance = 0;
rightGrandChild->balance = 0;
tree = rightGrandChild;
*ht_dec = TRUE;
}
else {
*ht_dec = FALSE;
}
break;
}
return tree;
}``` i am guessing the porblem lies here