/**
   * Internal method to handle duplicates into a subtree.
   *
   * @param x the item to insert.
   * @param t the node that roots the tree.
   * @return the new root.
   * @throws DuplicateItemException if x is already present.
   */
  protected BinaryNode<AnyType> duplicate(AnyType x, BinaryNode<AnyType> t) {

    if (t == null) {
      t = new BinaryNode<AnyType>(x);
    } else {
      t.duplicate = duplicate(x, t.duplicate);
    }

    return t;
  }
 /**
  * Internal method to insert into a subtree.
  *
  * @param x the item to insert.
  * @param t the node that roots the tree.
  * @return the new root.
  * @throws DuplicateItemException if x is already present.
  */
 protected BinaryNode<AnyType> insert(AnyType x, BinaryNode<AnyType> t) {
   if (t == null) t = new BinaryNode<AnyType>(x);
   else if (x.compareTo(t.element) < 0) t.left = insert(x, t.left);
   else if (x.compareTo(t.element) > 0) t.right = insert(x, t.right);
   else {
     t.increaseDuplicateCount();
     t.hasDuplicate = true;
     t.duplicate = duplicate(x, t.duplicate);
   }
   return t;
 }