#ifndef _PTRSET_H #define _PTRSET_H #include "bool.h" #include enum mode { SNext = 0, SPrevious = 1, SExact, SInsert }; template class PtrSet; template class PtrSetEl { private: PtrSetEl *child[2]; const PtrSetEl *father; T *item; PtrSetEl(T *newitem, const PtrSetEl *f = (const PtrSetEl *) NULL); PtrSetEl(const PtrSetEl ©, const PtrSetEl *f = (const PtrSetEl *) NULL); ~PtrSetEl(); T *search(T *key, mode notfound); void print(int depth); friend class PtrSet; }; template class PtrSet { private: PtrSetEl *root; const PtrSetEl *current; public: PtrSet(); ~PtrSet(); PtrSet(const PtrSet ©); T *search(T *key, mode notfound); bool contains(T *key) { return NULL != search(key, SExact); }; void clear() { if ( NULL != root ) { delete root; root = (PtrSetEl *) NULL; current = (const PtrSetEl *) NULL; } }; bool first(mode dir = SNext); bool last() { return first(SPrevious); }; bool next(mode dir = SNext); bool prev() { return next(SPrevious); }; T *cur() const { return NULL != current ? current->item : (T *) NULL; }; void print(); }; #endif