Exemplo n.º 1
0
            /**
             * Removes the node at a given position.
             *
             * @param index is the index of the element to be removed relative to the position of
             * the parent node of the current node.
             */
            internal AVLNode remove(int index)
            {
                int indexRelativeToMe = index - relativePosition;

                if (indexRelativeToMe == 0)
                {
                    return(removeSelf());
                }
                if (indexRelativeToMe > 0)
                {
                    setRight(right.remove(indexRelativeToMe), right.right);
                    if (relativePosition < 0)
                    {
                        relativePosition++;
                    }
                }
                else
                {
                    setLeft(left.remove(indexRelativeToMe), left.left);
                    if (relativePosition > 0)
                    {
                        relativePosition--;
                    }
                }
                recalcHeight();
                return(balance());
            }