#include template class Link { public: Link* prev, next; T value; public: Link(const T& v, Link* p = NULL, Link* n = NULL) : value(v), prev(p), next(n) { }; }; template class CDList { protected: Link* head, tail; public: CDList(T value) : head(NULL), tail(NULL) { add(value); } void add(T value) { Link* element = new Link(value, tail, null); if(head == NULL) head = element; if(tail != NULL) tail->next = element; else tail = element; } T& getHead() { // because we return a reference, we can't return null if the list is empty // need to add an isEmpty() func. assert(head != NULL); if(head != NULL) return head->value; } void printBack() { Link* iterator = tail; while(iterator != NULL) { std::cout << iterator << " "; iterator = iterator->prev; } } };