Example #1
0
        private AVLTreeNode <K, V> balance()
        {
            if (m_parent != null)
            {
                m_parent.updateHeight();
            }

            if (getParent(m_parent) != null &&
                isParentsLeft(this) != isParentsLeft(m_parent) &&
                m_height > getHeight(getSibbling(this)))
            {
                rotate();

                return(balance());
            }

            AVLTreeNode <K, V> nextNode = this;

            int diff = getHeight(m_left) - getHeight(m_right);

            if (Math.Abs(diff) > 1)
            {
                nextNode = getChild(this, diff > 0);

                nextNode.rotate();
            }

            if (nextNode.m_parent != null)
            {
                return(nextNode.m_parent.balance());
            }
            else
            {
                return(this);
            }
        }
Example #2
0
 isParentsLeft(AVLTreeNode <K, V> p_node)
 {
     return(getChild(getParent(p_node), true) == p_node);
 }
Example #3
0
 public AVLTree()
 {
     m_root = null;
     m_size = 0;
 }