// Iterator for Set class #ifndef _SETITER_H #define _SETITER_H #include "Set.cpp" #include "Node.cpp" #include using std::cerr; using std::endl; template < class T > class SetIter { private: const Set < T > &theSet; // reference to Set object const Node < T > *cursor; // points to next element public: SetIter(const Set < T > &aSet):theSet(aSet), cursor(aSet.myset) { }; T next(); bool hasNext() { return cursor; }; void reset() { cursor = theSet.myset; }; }; template < class T > T SetIter < T >::next() { T temp; if (cursor) { temp = cursor->info; cursor = cursor->next; } else cerr << "error: iterator is done" << endl; return temp; } #endif