#ifndef MYLIST_H #define MYLIST_H // Note: There is never an implementation file (*.C) for a template class template class MyList { public: MyList *next; T *data; public: MyList(); MyList(T *p); ~MyList(); void insert(T *p); void clearList(); void destroyList(); void catList(MyList *p); void CloneList(MyList *p); }; template MyList::MyList() { data = 0; next = 0; } template MyList::MyList(T *p) { data = p; next = 0; } template MyList::~MyList() { } template void MyList::insert(T *p) { MyList *ct = this; if (data == 0) { data = p; } else { while (ct->next) { ct = ct->next; } ct->next = new MyList(p); ct = ct->next; ct->next = 0; } } template void MyList::clearList() { MyList *ct = this, *n; while (ct) { n = ct->next; delete ct; ct = n; } } template void MyList::destroyList() { MyList *ct = this, *n; while (ct) { n = ct->next; delete ct->data; delete ct; ct = n; } } template void MyList::catList(MyList *p) { MyList *ct = this; while (ct->next) { ct = ct->next; } ct->next = p; } template void MyList::CloneList(MyList *p) { MyList *ct = this; p = 0; while (ct) { if (!p) p = new MyList(ct->data); else p->insert(ct->data); ct = ct->next; } } #endif /* MyList_H */