|
|
COT 5410-01 Fall 2004 Algorithms Chris Lacher Notes 6: Associative ADTs: Set, Map, Table, AssociativeArray |
//--------------------------
// class Set<T,C>
//--------------------------
template < typename T , class C >
class Set
{
public:
// Access support: SetIterator
// Terminology support: value_type, Iterator
// Proper type: constructors, destructors, assignment
// element operations - modality determined by C
Iterator Insert (const value_type& t);
size_t Remove (const value_type& t);
// locator operations
Iterator Includes (const value_type& t) const;
Iterator Begin () const;
Iterator End () const;
Iterator rBegin () const;
Iterator rEnd () const;
// size operations
int Empty () const;
size_t Size () const;
protected:
C c;
} ; // class Set
//----------------------------------
// class SetIterator<T,C>
//----------------------------------
template <typename T , class C>
class SetIterator
{
public:
// Access support: Set
// Terminology support: value_type
// Proper type: constructors, destructors, assignment
// operators
int operator == (const SetIterator<T,C>& I2) const;
int operator != (const SetIterator<T,C>& I2) const;
value_type& operator * () const; // Return reference to current value
SetIterator<T,C>& operator = (const SetIterator <T,C> & I);
SetIterator<T,C>& operator ++ (); // prefix
SetIterator<T,C> operator ++ (int); // postfix
SetIterator<T,C>& operator -- (); // prefix
SetIterator<T,C> operator -- (int); // postfix
protected:
typename C::Iterator i;
} ; // class SetIterator
for (C::Iterator I = c.Begin(); I != c.End(); ++I)
{
// any code in the body
}
Data& operator [] (const Key& k);