Пример #1
0
 /**
  * Add a number in the subtree of this node
  */
 public void Insert(int _value)
 {
     if (_value < this.Value)
     {
         // Smaller value, insert it into the left subtree
         if (this.Left == null)
             this.Left = new BT_Node(this, _value);
         else
             this.Left.Insert(_value);
     }
     else
     {
         // Larger value, insert it in the right subtree
         if (this.Right == null)
             this.Right = new BT_Node(this, _value);
         else
             this.Right.Insert(_value);
     }
 }
Пример #2
0
        public bool Remove(int _value, BT_Node parent)
        {
            if (_value < this.value)
            {
                if (left != null)
                    return left.Remove(_value, this);
                else
                    return false;
            }
            else if (_value > this.value)
            {
                if (right != null)
                    return right.Remove(_value, this);
                else
                    return false;
            }
            else
            {
                if (left != null && right != null)
                {
                    this.value = right.minValue();
                    right.Remove(this.value, this);
                }
                else if (parent.left == this)
                {
                    parent.left = (left != null) ? left : right;
                }
                else if (parent.right == this)
                {
                    parent.right = (left != null) ? left : right;
                }

                return true;

            }
        }
Пример #3
0
 public BT_Node(BT_Node _parrent, int _value)
 {
     this.Value = _value;
     this.Parrent = _parrent;
 }