// L-12 MCS 360 Mon 20 Sep 2010 : mcs360_double_list.tc /* This file defines the member function of the templated class List in the namespace mcs360_double_list. */ #include namespace mcs360_double_list { template List::List() { first = NULL; last = NULL; } template List::List(T item) { first = new Node(item); last = first; } template void List::append(T item) { if(first == NULL) { first = new Node(item); last = first; } else if(first == last) { first->next = new Node(item); first->next->prev = first; last = first->next; } else { last->next = new Node(item); last->next->prev = last; last = last->next; } } template void List::write_forward() { Node *ptr = first; while(ptr != NULL) { std::cout << "->" << ptr->data; ptr = ptr->next; } } template void List::write_backward() { Node *ptr = last; while(ptr != NULL) { std::cout << "->" << ptr->data; ptr = ptr->prev; } } }