Exemplo n.º 1
0
    public BinaryNode remove(T e) {

      if (data.compareTo(e) > 0) {
        if (left == null) {
          removed = false;
          return this;
        }
        left = left.remove(e);
      } else if (data.compareTo(e) < 0) {
        if (right == null) {
          removed = false;
          return this;
        }
        right = right.remove(e);
      }
      int leftLevel = 0;
      int rightLevel = 0;
      if (this.left != null) {
        leftLevel = left.level;
      }
      if (this.right != null) {
        rightLevel = right.level;
      }
      if (this.data.compareTo(e) == 0) {
        this.data = null;
        level = 0;
        return this;
      }

      if ((leftLevel < this.level - 1) || (rightLevel < this.level - 1)) {
        removed = true;
        BinaryNode temp = right.getMin();
        if (right.level < level - 1) {
          level -= 1;
          if (right.level > level) {
            right.level = level;
          }
          skew();
          right.skew();
          right.right.skew();
          split();
          right.split();
        }
      }
      return this;
    }
Exemplo n.º 2
0
  public Boolean remove(T obj) {
    if (obj == null) {
      removed = false;
      throw new IllegalArgumentException();
    }

    if (root == null) {
      return removed;
    }

    root = root.remove(obj);
    return removed;
  }