Helllo,,please,help me,to write programm add balance,delete balance in search tree,

TreeNode *AddBalance (Type x,TreeNode *root,int *grow)
{int  incr;
 *grow = 0;
 if (!root)
 {root=(TreeNode*) GetPlace();
  if (root)
  {root->left=root->right=0;
   root->value=x; root->balance=0;
   *grow=1;
  }
   return root;
  }
  if (x<=root->value)
    {root->left=AddBalance(x,root->left,&incr);
     if (incr)
       {switch(root->balance)
          {case  0:root->balance=-1;*grow=1;break;
           case  1:root->balance=0;break;
           case -1:
              switch(root->left->balance)
                {case -1:root=Rebuild_L1(root);break;
                 case  1:root=Rebuild_L2(root);
              }
        }
     }
}
 else {root->right=AddBalance(x,root->right,&incr);
       if(incr)
        {switch(root->balance)
           {case  0:root->balance=-1;*grow=1;break;
            case -1:root->balance=0;break;
            case  1:
               switch(root->right->balance)
                 {case  1:root=Rebuild_L1(root);break;
                  case -1:root=Rebuild_L2(root);

               } 
         } 
                 }

        }
         return root;
}

Edited 3 Years Ago by mike_2000_17: Fixed formatting

This article has been dead for over six months. Start a new discussion instead.