Ejemplo n.º 1
0
 public override void setLeftChild(MyTreeSet <T> left)
 {
     this.leftChild = (MyTreeSetImpl <T>)left;
 }
Ejemplo n.º 2
0
 public bool deleteNode(MyTreeSetImpl <T> node, T value)
 {
     if (node.getRoot() == false)
     {
         return(false);
     }
     if (node.comparator.Compare(value, node.getValue()) == 0)
     {
         if (node.getLeftChild() == null && node.getRightChild() == null)
         {
             if (this.parent != null)
             {
                 if (this.right == true)
                 {
                     this.parent.setRightChild(this.changeNode);
                 }
                 else
                 {
                     this.parent.setLeftChild(this.changeNode);
                 }
             }
             else
             {
                 node.setRoot(false);
             }
             return(true);
         }
         if (null != node.getLeftChild() && null != node.getRightChild())
         {
             this.right = false;
             this.left  = false;
             node.setValue(minNodeValue(node));
             return(true);
         }
         if (node.getLeftChild() != null)
         {
             if (this.parent != null)
             {
                 if (this.left == true)
                 {
                     this.parent.setLeftChild(node.getLeftChild());
                 }
                 else
                 {
                     this.parent.setRightChild(node.getLeftChild());
                 }
                 return(true);
             }
             else
             {
                 node.setValue(node.getLeftChild().getValue());
                 node.setLeftChild(this.changeNode);
                 return(true);
             }
         }
         if (node.getRightChild() != null)
         {
             if (this.parent != null)
             {
                 if (this.right == true)
                 {
                     this.parent.setRightChild(node.getRightChild());
                 }
                 else
                 {
                     this.parent.setLeftChild(node.getRightChild());
                 }
                 return(true);
             }
             else
             {
                 node.setValue(node.getRightChild().getValue());
                 node.setRightChild(this.changeNode);
                 return(true);
             }
         }
     }
     this.parent = node;
     if (node.comparator.Compare(node.getValue(), value) > 0)
     {
         this.left  = true;
         this.right = false;
         return(deleteNode((MyTreeSetImpl <T>)node.getLeftChild(), value));
     }
     if (node.comparator.Compare(node.getValue(), value) < 0)
     {
         this.right = true;
         this.left  = false;
         return(deleteNode((MyTreeSetImpl <T>)node.getRightChild(), value));
     }
     return(false);
 }