/* File: sl_list.H Copyright glh 9/15/92 */ #ifndef SLISTH #define SLISTH #include #include #include typedef enum {false, true} Boolean; // forward references for template classes template class SlList; template class SlListIterator; template class SlNode { friend class SlList; friend class SlListIterator; friend ostream& operator<<(ostream&, const SlList&); private: T data; SlNode* next; SlNode() {} inline SlNode(const T&); }; template inline SlNode::SlNode(const T& elm) {data = elm;} template class SlList { friend class SlListIterator; protected: int length; SlNode* tail; // tail->next is the head of the list public: inline SlList(); SlList(const T&); SlList(const SlList&); inline ~SlList(); SlList& operator=(const SlList&); friend ostream& operator<<(ostream&, const SlList&); void Insert(const T&, int); void Append(const T&); T& Retrieve(int) const; void Delete(int); inline int Length() const; inline Boolean Empty() const; void MakeEmpty(); }; template inline SlList::SlList() {length=0; tail=NULL;} template inline SlList::~SlList() {MakeEmpty();} template inline int SlList::Length() const {return length;} template inline Boolean SlList::Empty() const {return length == 0 ? true : false;} template class SlListIterator { private: int current; const SlList* list; public: SlListIterator() {} SlListIterator(const SlList* lst); int Reset(); inline int Current() const; int operator++(); //prefix int operator++(int); //postfix }; template inline int SlListIterator::Current() const {return current;} #endif