//simple linked list #ifndef LIST_H #define LIST_H #include "node.h" class List { private: Node *front; Node* pos; Node * FindNode(Node*, Node*); public: List(); List(List&); // copy constructor ~List(); // desctructor bool IsFull(); bool IsEmpty(); void GetNext(Node &); void AddAtFront(Node &); void AddAtRear(Node &); void InsertBefore(Node &); // before node pointed to by pos void InsertInOrder(Node &); // order determined by Node::CompareTo void DeleteItem(); void FindItem(Node &, bool &); void Reset(); bool EndOfList(); List& operator=(List&); // overloaded assignment operator void Print(); }; #endif #include "list.h" #include "node.h" #include #include #include using namespace std; List::List() { pos=0; front=0; } List::~List() { cout <<"destructor called " << endl; Node * temp; while(front != 0) { temp=front->next; cout << front->data << " "; delete front; front= temp; } cout << endl; } List& List::operator=(List & L) { if(this==&L) return *this; Node n; front=0; pos=0; Node * temp=0; Node * start; start = L.front; while(start != temp) { temp=FindNode(start,temp); if(temp==0) { break; } AddAtFront(*temp); } return *this; } Node * List::FindNode(Node* start, Node * end) { Node * temp=start; Node * test; while(temp !=end) { test=temp->next; if(test ==end) { return temp; } else { temp=test; } } return end; } List::List(List & L) { // cout <<" callign copy constructor " << endl; Node n; front=0; pos=0; Node * temp=0; Node * start; start = L.front; while(start != temp) { temp=FindNode(start,temp); if(temp==0) { return; } AddAtFront(*temp); } } bool List::IsFull() { /* try { Node * temp = new Node(); delete temp; return false; } catch (bad_alloc e) { return true; } */