Exemplo n.º 1
0
 public void Delete()
 {
     if (parent == null)
     {
         ranges.DeleteRange(range);
     }
     else
     {
         if (left == null && right == null)
         {
             // deleting a leaf
             parent.ReplaceChild(this, null);
         }
         else if (left == null)
         {
             parent.ReplaceChild(this, right);
         }
         else if (right == null)
         {
             parent.ReplaceChild(this, left);
         }
         else  // left and right are not null
         {
             BST successor = GetSuccessor(this);
             this.range = successor.range;
             successor.Delete();
         }
     }
 }