Exemplo n.º 1
0
 public void calculateBalance(AVLTreeNode node)
 {
     if (node.left != null && node.right != null)
     {
         node.balance = (balanceFactor)(node.depthRight() - node.depthLeft());
         if (node.balance == balanceFactor.MinusMinus || node.balance == balanceFactor.PlusPlus)
         {
             compensate(node);
         }
     }
     else if (node.left != null)
     {
         node.balance = (balanceFactor)(-node.depthLeft());
         if (node.balance == balanceFactor.MinusMinus)
         {
             compensate(node);
         }
     }
     else if (node.right != null)
     {
         node.balance = (balanceFactor)(node.depthRight());
         if (node.balance == balanceFactor.PlusPlus)
         {
             compensate(node);
         }
     }
     else
     {
         node.balance = 0;
     }
 }
Exemplo n.º 2
0
            public int depth()
            {
                int mydl = 0;
                int mydr = 0;

                if (left != null)
                {
                    mydl = left.depthLeft() + 1;
                }
                else
                {
                    mydl = 0;
                }

                if (right != null)
                {
                    mydr = right.depthRight() + 1;
                }
                else
                {
                    mydr = 0;
                }

                return(mydl > mydr ? mydl : mydr);
            }