// File: List.h // Linked List class with List Iterator class #ifndef _LIST_ #define _LIST_ #include class node { private: node( int d = 0, node* p = NULL ) : data(d), next(p) {}; int data; node* next; friend class list; friend class listItr; }; class list { public: list(); ~list(); list(list&); list& operator=( const list& ); bool empty( void ); bool find( int ); void insertFirst( int ); void orderedInsert( int ); int removeFirst( void ); void remove( int ); list operator+( const list& ); int *operator[](int); int operator+(); int countNodesInList(); void sort(void); void mystery(); private: node* head; node* copy( node* ); void destroy( node* ); int removeIt( node* & ); int countNodes(node *); friend ostream& operator<<( ostream&, const list& ); friend class listItr; }; class listItr { public: listItr(const list &l):itr(l),curr(l.head) {}; void start(void) {curr = itr.head;} bool more(void) {return curr != NULL;} void next(void) {assert( curr != NULL ); curr = curr->next; } int value(void) {assert( curr != NULL ); return curr->data; } private: const list& itr; node* curr; }; #endif