// -------------------------------------------------------------------------- // Linear Containers // A. Fischer June 12, 2001 file: linear.hpp // -------------------------------------------------------------------------- #pragma once #include #include "container.hpp" #include "cell.hpp" #include "item.hpp" using namespace std; class Linear: public Container { protected: // ------------------------------------------------------------- Cell* head; // This is a dummy header for the list. private: // ------------------------------------------------------------- Cell* here; // Cursor for traversing the container. Cell* prior; // Trailing pointer for traversing the container. protected: // ------------------------------------------------------------- Linear(): head(new Cell), here( NULL ), prior( head ) {} virtual ~Linear (); void reset() { prior = head; here = head->next; } bool end() const { return here == NULL; } void operator ++(); virtual void insert( Cell* cp ); virtual void focus() = 0; Cell* remove(); void setPrior(Cell* cp){ prior = cp; here = prior->next; } bool operator< ( Cell* cp ) { return (*cp->data < *here->data); } bool operator< ( KeyType k ){ return *here->data < k; } bool operator== ( KeyType k ){ return *here->data == k; } public: // -------------------------------------------------------------- void put(Item * ep) { if (ep) insert( new Cell(ep) ); } Item* pop(); Item* peek() { focus(); return *here; } virtual ostream& print( ostream& out ); }; inline ostream& operator<<(ostream& out, Linear& s) {return s.print(out); }