class IntSet { private: enum { MAXVALUES = 4 }; int data [MAXVALUES]; int count; // number of values currently in the set bool walkInProgress; int walkPosition; // position of last value returned public: // constructs an empty set. // for really trivial constructors and methods, the complete // implementation is often placed directly in the class definition. IntSet () { count = 0; walkInProgress = false; } // adds a value to the set. has no effect if the value is already in the // set. throws an "overflow_error" if the value cannot be added to the set. void add (int value); // removes one occurrence of the specified value from the set. returns // true on success (value existed) and false on failure (value did not exist) bool remove (int value); // removes all values from the set (makes the set empty) void removeAll (); // returns true if the value exists in the set and false otherwise bool valueExists (int value) const; // returns the number of values in the set. int size () const { return count; } // These two methods make it possible to "walk through" the values in a // set. The values in the set may be returned in any order. There is no // guarantee that they will be returned in numerical order, in the order in // which they were entered, or any other particular order. "startWalk" may // be called at any time. If returns true on success (value obtained) and // false on failure (set empty). "continueWalk" may only be called if // 1/. the set has not been modified since a walk was // begun by calling startWalk AND // 2/. the last call to startWalk or ContinueWalk returned true // If these conditions are not met, "contiinueWalk" throws a "range_error" // exception. It returns true on success (value obtained) and false on // failure (no more values). bool startWalk (int &value); bool continueWalk (int &value); // returns true iff the two sets contain exactly the same values bool operator== (const IntSet &otherSet) const; // returns the intersection of two sets IntSet intersect (const IntSet &otherSet) const; // returns the union of two sets. throws an "overflow_error" if the // union of the sets is too large to be handled. IntSet unionWith (const IntSet &otherSet) const; };