Commit 6f1440f9 authored by Ari Trachtenberg's avatar Ari Trachtenberg
Browse files

Updated signatures

parent c5545d44
Loading
Loading
Loading
Loading
+6 −4
Original line number Diff line number Diff line
@@ -100,7 +100,7 @@ public class BST<keyType extends Comparable<keyType> > {
     */
    public BST(keyType theKey) {
        this();
        insert(theKey);
        add(theKey);
    }

    /**
@@ -112,7 +112,7 @@ public class BST<keyType extends Comparable<keyType> > {
    public BST(Iterable<keyType> keys) {
        this();
        for (keyType key : keys) {
            insert(key);
            add(key);
        }
    }

@@ -190,14 +190,15 @@ public class BST<keyType extends Comparable<keyType> > {
     * Inserts the new number as a key into the binary search tree
     *
     * @param newKey The new key to be inserted.
     * @return
     */
    public void insert(keyType newKey) {
    public boolean add(keyType newKey) {
        searchRecord theRecord = searchHelper(newKey);

        if (theRecord == null) // insert here
            key = newKey;
        else if (theRecord.searchResult) // the item is already in the tree
            throw new IllegalStateException(newKey + " is already in this data structure");
            return false; // newKey is already in this data structure
        else {
            // put into the appropriate child
            BST<keyType> lastSeen = theRecord.lastSeen;
@@ -206,6 +207,7 @@ public class BST<keyType extends Comparable<keyType> > {
            else
                lastSeen.leftChild = new BST<>(newKey);
        }
        return true;
    }

    // ... informational
+0 −8
Original line number Diff line number Diff line
@@ -50,14 +50,6 @@ public class BSTSet<keyType extends Comparable<keyType>> extends BST<keyType> im
    return null;
  }

  /**
   * @inheritDoc
   */
  @Override
  public boolean add(keyType keyType) {
    return false;
  }

  /**
   * @inheritDoc
   */
+3 −2
Original line number Diff line number Diff line
@@ -30,10 +30,11 @@ public class ExtendedBSTSet<keyType extends Comparable<keyType>> extends BSTSet<

  /**
   * @inheritDoc
   * @return
   */
  @Override
  public void insert(keyType newKey) {
    super.insert(newKey);
  public boolean add(keyType newKey) {
    return super.add(newKey);
  }

  /**