#include "myList.h" template void List::add(Type &newData) { Node *newNode = new Node(&newData); if(head != 0) { newNode->next = head; head = newNode; noEntries++; } else { newNode->next = head; head = newNode; tail = newNode; noEntries++; } } template void List::push_back(Type &newData) { Node *newNode = new Node(&newData); if(head != 0) { tail->next = newNode; tail = newNode; noEntries++; } else { tail = newNode; head = newNode; noEntries++; } } //start at the head of the list //delete items as you move along //stop when at the end i.e. when //the next pointer value is 0 /*template List::~List() { while(head!=0) { Node *temp = head; head = head->next; delete temp; //delete what temp points at! } }*/ template Type *List::at(int index) { Node *temp = head; int i; for(i = 0; i < index; ++i) { temp = temp->next; } return temp->dataItem; } template int List::size() { int i = 0; Node *temp = head; while(temp != tail) { ++i; } return i; } template void List::erase(int index) { Node *temp = at(index); delete temp; //Might actually need to use the destructor at this point in which case it would be //something like ~Node(temp); where that deletes all variables and references relating to temp }