Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- template <class TData>
- class PatternIterator
- {
- virtual bool hasNext() = 0;
- virtual TData next() = 0;
- virtual TData& operator* () = 0;
- };
- template <class TKey>
- class KHashTablePatternIterator : public PatternIterator<TKey>
- {
- int usedElems;
- int pos;
- friend KHashTable <TKey>;
- KHashTable <TKey> hashTable;
- public:
- KHashTablePatternIterator(KHashTable<TKey> &obj) : pos (0), usedElems(0), hashTable(obj) {}
- TKey next() {
- while (!hashTable.isUsed[pos]) { pos++; }
- TKey curElem = hashTable.table[pos];
- pos++;
- usedElems++;
- return curElem;
- }
- TKey& operator* () {
- while (!hashTable.isUsed[pos]) { pos++; }
- return hashTable.table[pos];
- }
- bool hasNext() { if (usedElems == hashTable.nSize) return false; else return true; }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement