// Queue.cpp #include "Queue.h" Node::Node (const ElemType& el) : elem_ (el), next_ (NULL) { } Queue::Queue () : front_ (NULL), back_ (NULL) { } bool Queue::isEmpty() const { return front_ == NULL; } void Queue::insert (const ElemType& el) { Node* temp = new Node (el); if (isEmpty()) { front_ = back_ = temp; } else { back_->next_ = temp; back_ = temp; } } const ElemType& Queue::front () const { if (!isEmpty()) return front_->elem_; else { cerr << "Cannot access the front of an Empty Queue" << endl; exit(1); // perhaps use of an exception is better } } void Queue::remove () { if (!isEmpty()) { Node* temp = front_; front = front_->next_; delete temp; } else { cerr << "Cannot remove an item from an empty queue" << endl; } } void Queue::clear() { while (!isEmpty()) remove(); } Queue::~Queue() { clear(); } Queue::Queue(const Queue& q) : front_ (NULL), back_ (NULL) { Node* temp = q.front_; while (temp != NULL) { insert(temp->elem_); temp = temp->next_; } } Queue& Queue::operator= (const Queue& rhs) { if (this == &rhs) return *this; // deallocate the nodes currently in this clear(); // create a copy of rhs Node* temp = rhs.front_; while (temp != NULL) { insert(temp->elem_); temp = temp->next_; } // return return *this; }