Exemplo n.º 1
0
        private void deleteNode(int data, BinaryNode currentRoot)
        {
            BinaryNode tempNode = search(data);

            if (tempNode.isLeaf())
            {
                if (position)
                {
                    parent.setLeftChild(null);
                }
                else
                {
                    parent.setRightChild(null);
                }
            }
            else if (tempNode.hasOneChild())
            {
                if (tempNode.getchildPosition())
                {
                    parent.setLeftChild(tempNode.getLeftChild());
                }
                else
                {
                    parent.setRightChild(tempNode.getRightChild());
                }
            }
            else
            {
                BinaryNode min = getMinor(tempNode.getRightChild());
                deleteNode(min.getData());
                tempNode.setData(min.getData());
            }
        }