class IntSequence { private: class DNode { // data node public: int data; DNode *next; DNode (int data, DNode *next) { this -> data = data; this -> next = next; } }; DNode *head, *tail; // head and tail pointers for linked list int count; // number of values currently in the Sequence bool walkInProgress; DNode *walkPointer; // pointer to last DNode processed // if the object is full, increases its capacity (no longer needed) // void expandIfFull (); // copies the data from the other sequence into the sequence being // operated upon. begins by setting "head" and "tail" to NULL, and // "count" to zero (i.e. the values of these member variables do not // matter). leaves "walkInProgress" false. void copyFrom (const IntSequence &otherSequence); // deletes all nodes in linked list. leaves "head" and "tail" set to // NULL and count set to 0. void deleteList (); void addAtEnd (int value); public: // constructs an empty sequence. IntSequence (); // copy constructor IntSequence (const IntSequence &otherSequence); // destructor ~IntSequence (); // adds a value to the sequence. has no effect if the value is already // in the sequence. throws an "overflow_error" if the value cannot be // added to the sequence. void add (int value); // removes the specified value from the sequence. returns true on success // (value existed) and false on failure (value did not exist) bool remove (int value); // removes all values from the sequence (makes the Sequence empty) void removeAll (); // returns true if the value exists in the sequence and false otherwise bool valueExists (int value) const; // returns the number of values in the sequence. int size () const { return count; } // returns the "ith" value in the sequence. int getValue (int i) const; // These two methods make it possible to "walk through" the values in a // sequence. The values in the sequence are returned in ascending // numerical order, in the order "startWalk" may // be called at any time. If returns true on success (value obtained) and // false on failure (sequence empty). "continueWalk" may only be called if // 1/. the sequence 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 sequences contain exactly the same values bool operator== (const IntSequence &otherSequence) const; // returns the intersection of two sequences IntSequence intersect (const IntSequence &otherSequence) const; // returns the union of two sequences. throws an "overflow_error" if the // union of the sequences is too large to be handled. IntSequence unionWith (const IntSequence &otherSequence) const; IntSequence& operator= (const IntSequence &otherSequence); };