#include using namespace std; //Once again the Node class works, fix the List Class template < class Item > Node::Node(Item data) : m_data(data) { next = NULL; } List::List() { m_head = new Node(/*Remember the node constructor takes an argument*/); } List::List(const List &rhs) { // Assign RHS into this List if(this != & rhs) { (*this) = rhs; } } List::~List() { clear(); delete m_head; } const List& List::operator=(const List &rhs) { if(this == &rhs) return *this; // we are going to be overwriting, so delete our old stuff clear(); Node * rhs_current = rhs.m_head; Node * current = m_head; while(rhs_current->next != NULL) { current->next = new Node(rhs_current->next->m_data); current = current->next; rhs_current = rhs_current->next; } return *this; } void List::insert( data) { Node* current = m_head; while(current->next != NULL) { //if(current->next->m_data > data || //I don't want the list ordered if(current->next == NULL) { Node* temp = current->next; current->next = new Node(data); current->next->next = temp; return; } current = current->next; } // insert at the end of the list current->next = new Node(data); } bool List::remove( data) { Node* current = m_head; while(current->next != NULL) { if(current->next->m_data == data) { Node* temp = current->next; current->next = current->next->next; delete temp; return true; } current = current->next; } return false; } void List::Print() const { Node* current = m_head; while(current->next != NULL) { cout << current->next->m_data << ' '; current = current->next; } } void List::clear() { // it's empty already! if(m_head->next == NULL) return; Node* previous = m_head->next; Node* current = m_head->next->next; m_head->next = NULL; while(current != NULL) { delete previous; previous = current; current = current->next; } } unsigned int List::size() const { unsigned int i = 0; Node* current = m_head->next; while(current != NULL) { current = current->next; i++; } return i; }