/* File: LinkedList.cpp Author: Matthew Small Description: Header file for a linked list that is templated to allow for storage of various data types. */ #include /* forward declarations, needed to allow template classes to work with friend functions */ template class ListElement; template class LinkedList; template std::ostream& operator<<(std::ostream&, const ListElement&); template std::ostream& operator<<(std::ostream&, const LinkedList&); /* A linked list element that holds a variable 'data' whose type is templated as T. */ template class ListElement { friend std::ostream& operator<< (std::ostream&, const ListElement&); public: DATA_TYPE data; /* data stored by this element (int, double, Mixed, etc.) */ ListElement *next; /* pointer to next element in list */ }; /* The linked list itself, this must also be templated. */ template class LinkedList { friend std::ostream& operator<< (std::ostream&, const LinkedList&); public: LinkedList(); ~LinkedList(); void AddToEnd(DATA_TYPE); void RemoveFromEnd(); void AddElementPos(DATA_TYPE, int); void RemoveElementPos(int); ListElement *head; /* head of linked list */ }; /**** The comment below should be well understood for the Final Exam. ****/ /* We include the implementation of the above templated classes below their declaration within this header file so that any file that includes this header also has access to the definitions. As we recall from lecture, different versions of templated functions and classes are compiled for each type used for 'typename T' and this happens during the compilation phase and not the linking phase (the linking phase is when non-template functions and class definitions are matched up with their uses). Because of these differences, the convention is to use the file type '.hpp' for files containing template implementations. */ #include "LinkedList.hpp"