示例#1
0
        /// <summary>
        /// Método para Alterar a própria referência.
        /// </summary>
        /// <param name="tree">Nó para atualizar a referência atual</param>
        private void setThisRef(AbstractBinaryTree tree)
        {
            // Verifica se o nó atual já é igual ao nó passado.
            if (!this.Equals(tree))
            {
                // Cria um nó auxiliar
                Splay aux = new Splay();
                // Atualiza valores
                aux.KEY    = KEY;
                aux.HEIGHT = HEIGHT;
                aux.setLeftChild(getLeftChild());
                aux.setRightChild(getRightChild());
                // Modifica a instância this, verificando se o valor do nó passado.
                switch (tree.KEY.VALUE.CompareTo(KEY.VALUE))
                {
                // Caso seja maior, o auxiliar vira filho a direita.
                case  1: key = tree.KEY;
                    height   = tree.HEIGHT;
                    setLeftChild(aux);
                    setRightChild(tree.getRightChild());
                    break;

                // Caso seja menor, o auxiliar vira filho a esquerda.
                case -1: KEY = tree.KEY;
                    height   = tree.HEIGHT;
                    setLeftChild(tree.getLeftChild());
                    setRightChild(aux);
                    break;
                }
            }
        }
示例#2
0
        public AbstractBinaryTree zag(AbstractBinaryTree tree)
        {
            Splay aux        = (Splay)tree;
            Splay rightChild = (Splay)tree.getRightChild();
            Splay subTree2   = (Splay)rightChild.getLeftChild();

            rightChild.setLeftChild(tree);
            tree.setRightChild(subTree2);

            updateHeight(tree);
            updateHeight(rightChild);

            return(rightChild);
        }