// File: LinkedList.h // Linked List class with List Iterator class #ifndef _LinkedList_ #define _LinkedList_ #include #include using namespace std; // Need to prototype template classes if they are to be friends template class LinkedList; // and also the friend...note <> in header declaration of << template ostream& operator<<(ostream&,const LinkedList &); template class node { private: node(eltType info= 0, node* link = NULL ) : data(info), next(link) {}; eltType data; node* next; friend class LinkedList; // why does the << have to be a friend? Can this be avoided? friend ostream& operator<< <>(ostream&,const LinkedList &); }; 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 &); }; #endif