#include "QueueLi.h" // Construct the queue. template Queue::Queue( ) { front = back = NULL; } // Copy constructor. template Queue::Queue( const Queue & rhs ) { front = back = NULL; *this = rhs; } // Destructor. template Queue::~Queue( ) { makeEmpty( ); } // Test if the queue is logically empty. // Return true if empty, false, otherwise. template bool Queue::isEmpty( ) const { return front == NULL; } // Make the queue logically empty. template void Queue::makeEmpty( ) { while( !isEmpty( ) ) dequeue( ); } // Return the least recently inserted item in the queue // or throw UnderflowException if empty. template const Object & Queue::getFront( ) const { if( isEmpty( ) ) throw UnderflowException( ); return front->element; } // Return and remove the least recently inserted item from // the queue. Throw UnderflowException if empty. template Object Queue::dequeue( ) { Object frontItem = getFront( ); ListNode *old = front; front = front->next; delete old; return frontItem; } // Insert x into the queue. template void Queue::enqueue( const Object & x ) { if( isEmpty( ) ) back = front = new ListNode( x ); else back = back->next = new ListNode( x ); } // Deep copy. template const Queue & Queue::operator=( const Queue & rhs ) { if( this != &rhs ) { makeEmpty( ); ListNode *rptr; for( rptr = rhs.front; rptr != NULL; rptr = rptr->next ) enqueue( rptr->element ); } return *this; }