Example #1
0
        public BSTNode delete(int value)
        {
            if (value < number)
            {
                if (left != null)
                {
                    left = left.delete(value);
                }
                return(this);
            }
            if (value > number)
            {
                if (right != null)
                {
                    right = right.delete(value);
                }
                return(this);
            }
            if (left == null && right == null)
            {
                return(null);
            }
            if (left == null)
            {
                return(right);
            }
            if (right == null)
            {
                return(left);
            }

            this.number = left.max();
            left.delete(this.number);
            return(this);
        }
Example #2
0
        public int max()
        {
            int highest = number;

            if (right != null)
            {
                highest = right.max();
            }
            return(highest);
        }
Example #3
0
 /**
  * Returns the largest value in the tree (or -1 if tree is empty)
  */
 public int max()
 {
     return(root.max());
 }