// FILE: vset.h (part of the namespace csci2270) // TEMPLATE CLASS PROVIDED: set // (a container class for a set of int numbers) // // TYPEDEFS for the set class: // set::value_type // Currently set to int // // CONSTRUCTOR for the set class: // set( ) // Postcondition: The set is empty. // // MODIFICATION MEMBER FUNCTIONS for the set class: // void clear( ) // Postcondition: The set is empty. // // bool insert(const Item& entry) // Postcondition: If an equal entry was already in the set, the set is // unchanged and the return value is false. Otherwise, entry was added // to the set and the return value is true. This is slightly different than // the C++ Standard Library set (see Appendix H). // // bool erase(const Item& target) // Postcondition: If target was in the set, then it has been removed from // the set and the return value is true. Otherwise the set is unchanged // and the return value is false. // // CONSTANT MEMBER FUNCTIONS for the Set class: // bool contains(const Item& target) const // Postcondition: Returns true if the target is in this set; otherwise false. // // bool empty( ) const // Postcondition: Returns true if the set is empty; otherwise returns false. // // VALUE SEMANTICS for the set class: // Assignments and the copy constructor may be used with set objects. // // DYNAMIC MEMORY USAGE by the set class: // If there is insufficient dynamic memory, then the following functions throw // bad_alloc: The constructors, insert, and the assignment operator. #ifndef VSET_H #define VSET_H #include // Provides size_t #include // Provides vector template class namespace csci2270 { class set { public: // TYPEDEFS typedef int value_type; // CONSTRUCTORS and DESTRUCTOR set( ); set(const set& source); ~set( ) { clear( ); } // MODIFICATION MEMBER FUNCTIONS void operator =(const set& source); void clear( ); bool insert(const value_type& entry); bool erase(const value_type& target); // CONSTANT MEMBER FUNCTIONS bool contains(const value_type& target) const; bool empty( ) const { return (data.size() == 0); } // SUGGESTED FUNCTION FOR DEBUGGING void print(int indent) const; private: // MEMBER CONSTANTS static const std::size_t MINIMUM = 200; static const std::size_t MAXIMUM = 2 * MINIMUM; // MEMBER VARIABLES std::vector data; std::vector child; // NOTE: The implementor may want to have some helper functions. }; } #endif