#ifndef TmpLIST__SEEN #define TmpLIST__SEEN /////// File: List.h /////// #include // linked list template // forward teamplate class declaration template class Cell; template class ListIterator; // type T must define operator== and overload << template class List { friend class ListIterator; public: List() : head(NULL) { } // empty list constructor List(T& c) // list with first cell //: head (new Cell(c,NULL)) { } : head (new Cell(c)) { } Cell* first() { return head; } // first cell static Cell* next(Cell* p) // next cell { return (p ? p->next : p); } static int is_end(Cell* p) // end test { return(p == NULL); } Cell* last(); // last cell Cell* find(T& c); // first value equals c int substitute(T& r, T& s); // r for first s on list int remove(T& c); // c from entire list void remove(Cell* cell); // remove given cell int shorten(int n); // remove first n cells static T& content(Cell* p) { return p->value(); } int put_on(T& c); // insert in front int insert(T& c, Cell* cell); // insert after cell int append(T& c) // insert at end { return insert(c, last()); } int is_empty() { return(is_end(head)); } void display(ostream& out, // display from p to end Cell* p) const; void display(ostream& out) const { display(out, head); } // display whole list ~List(); // destructor private: int equal(T&, T&); // equality test Cell* head; // first cell of list void free(); // free all cells }; template class ListIterator { public: ListIterator(List& x) : l(x) { cur = pre = x.first(); } int operator()(T& n); // returns next entry in n void del(); // erases last retrieved entry from list private: List& l; Cell* cur; Cell* pre; }; template class Cell { friend class List; friend class ListIterator; private: T& value() { return(*val); } void value(T& v) { val = &v; } // set value T* val; // store pointer to type T Cell* next; Cell(T& c, Cell* ptr = NULL) : val(&c), next(ptr) { } // constructor }; #endif