// File: LinkedList.h // Linked List class with List Iterator class #ifndef _LinkedList_ #define _LinkedList_ #include // Need to prototype template classes if they are to be friends template class LinkedList; template class listItr; template class node { private: node(eltType info= 0, node* link = NULL ) : data(info), next(link) {}; eltType data; node* next; friend class LinkedList; friend class listItr; }; template class LinkedList { public: // Construct empty LinkedList LinkedList(); // Construct deep copy of another LinkedList LinkedList(LinkedList&); // destroy LinkedList ~LinkedList(); // Assign another LinkedList to this LinkedList; deep copy LinkedList& operator=(const LinkedList&); // Is the LinkedList empty? bool empty(); bool find(eltType); // Ordered insert/remove void orderedInsert(eltType); void remove(eltType); // Concatenate LinkedLists LinkedList operator+( const LinkedList& ); // Return pointer to data part of as node (not the data itself) eltType *operator[](int); // Quick example of recursion int countNodesInList(); // Hmmmmm...... void mystery(); private: // linked list pointer node* head; // Get a copy of a (deep) node node* copy(node *); // Free nodes of a linked list void destroy(node *); // Need this to count nodes in LinkedList int countNodes(node *); // Linked list to ostream friend ostream& operator<<(ostream&, const LinkedList &); // Needed to use a list iterator friend class listItr; }; // Set up an iterator; // an object that provides a pointer to a linked list (in this case) template class listItr { public: // Construc a List Iterator listItr(const LinkedList &l); // Set curr to point at the first node of itr void start(); // Is curr null? bool more(); // Go to curr->next void next(); // Get the value out of curr's node eltType value(); private: const LinkedList &itr; node* curr; }; #endif