#include "Queue.h" #include Queue& Queue::insert(const ElemType& el) { Node* pNode = new Node(el); if (isEmpty()) front = back = pNode; else { back->next = pNode; back = pNode; } return *this; } ElemType Queue::remove() { if (isEmpty()) { cerr << "Cannot remove an element from an empty queue" << endl; exit(1); } Node* pNode = front; front = front->next; ElemType retElem(pNode->elem); delete pNode; return retElem; } Queue::~Queue() { while (! isEmpty() ) remove(); } ostream& operator<< (ostream& ostr, Queue &rhs) { bool firstLoop = true; Node* pNode = rhs.front; while (pNode != NULL) { if (firstLoop) firstLoop = false; else ostr << "->"; ostr << pNode->elem; pNode = pNode->next; } ostr << "."; return ostr; }