#include // A bag is a collection in which an item can appear more than once. // This is an implementation of a bag of integers. The operations are // a constructor, a destructor, predicates full and empty, and an // iterator and a way to reset it, an insertion, a deletion, and a // predicate to test if a given integer is in the bag. // Data: // Basis: X is a bounded intbag <=> X is a bag of integers. // Invariant: X never has more than MAX elements in it. const int MAX = 20; // Default size class intbag { int * data; int size; int cursor; // Operations: public: intbag(void); // pre: None // post: An integer bag object is created. ~intbag(void); // pre: None // post: The object is destroyed and its memory recovered. int count(void); // pre: None // post: result = the number of elements in the object. int full(void); // pre: None // post: result = 0 if the object is not full, 1 otherwise. int empty(void); // pre: None // post: result = 0 if the object is not empty, 1 otherwise. void insert(int x); // pre: The object is not full // post: x appears once more in the object than it did before the call void remove(int x); // pre: None // post: if x was in the object before the call, it appears one less time. // If it was not in the object before the call, no action is taken. int has(int x); // pre: None // post: If x is in the object, result = 1, otherwise result = 0. int * next(void); // pre: None // post: result = a pointer to the next integer in the bag. NULL is // returned if the last integer has already been returned. Calls // to next are guaranteed to eventually return all elements in // the bag exactly once. No inserts or removes may be done between // subsequent calls to next. void resetcursor(void); // pre: None // post: The 'next' routine starts fresh from the beginning of the bag. };