Example #1
0
 /**
  * @modifies this
  * @effects removes the first occurrence of x in this, if any, as determined by .equals. Returns
  *     true if any elements were removed. In the worst case, this runs in linear time with respect
  *     to size().
  */
 public boolean remove(Object x) {
   for (int i = 0; i < getSize(); i++) {
     if (x.equals(get(i))) {
       remove(i);
       return true;
     }
   }
   return false;
 }
Example #2
0
 /**
  * @modifies this
  * @effects removes all occurrences of x in this, if any, as determined by .equals. Returns true
  *     if any elements were removed. In the worst case, this runs in linear time with respect to
  *     size().
  */
 public boolean removeAll(Object x) {
   boolean ret = false;
   for (int i = 0; i < getSize(); i++) {
     if (x.equals(get(i))) {
       remove(i);
       i--;
       ret = true;
     }
   }
   return ret;
 }