#include "stdstuff.h" #include "IntBag.h" // note that the constructor and size are not mentioned here as their // implementations are completely specified in the header file // adds a value to the bag. returns true on success (space available) // and false on failure (bag full) bool IntBag::add (int value) { if (count == MAXVALUES) return false; data[count++] = value; walkInProgress = false; // scrub any ongoing walk return true; } // removes one occurance of the specfied value from the bag. returns // true on success (value existed) and false on failure (value did not exist) bool IntBag::remove (int value) { int i; for (i = 0; i < count; i++) { if (data[i] == value) { // we've found the data value. // overwrite it with the last data value and adjust the count // to reflect the fact that there are now one fewer values in // the bag. note that this works even if the value being removed // is the last value in the bag. data[i] = data[--count]; walkInProgress = false; // scrub any ongoing walk return true; } } return false; } // removes all occurrences of the specified value, returns // the number of occurrences removed int IntBag::removeAll (int value) { int numTimes = countOccurrences(value); for (int i=0; i