/* This is the header file for the Queue library.

-----------------------------------------------------------------*/

#ifndef QUEUE
#define QUEUE

#include "LinkedList.h"

#include <assert.h>

#include "Boolean.h"

class Queue : private LinkedList
{
 public:

   /* --- Class Constructor ---

      Precondition:  A queue has been defined.
      Postcondition: The queue has been constructed as an empty queue.
   ------------------------------------------------------------------*/

   Queue(void) : LinkedList()
   {}


   /* --- Copy Constructor ---

      Precondition:  The compiler needs a copy of a Queue Q.
      Receive:       Q, the Queue to be copied
      Postcondition: The Queue containing this function is
                        a copy of Q.
   ----------------------------------------------------------------*/

   Queue(const Queue& Q) : LinkedList(Q)
   {}


   /* --- Is the Queue empty? ---

      Return: True iff the Queue containing this function is empty
   ----------------------------------------------------------------*/

   Boolean Empty(void) const
   {
      return (Length() == 0);
   }


   /* --- Is the Queue full? ---

      Return: True iff the Queue containing this function is full
   ----------------------------------------------------------------*/

   Boolean Full(void) const
   { return False; }    // a run-time allocated queue is "never" full


   /* --- Add an element to the queue ---

      Receive: Elem, the Element to be added
      Return:  The Queue containing this function, with Elem added
                  at the rear
   ----------------------------------------------------------------*/

   void Add(const ListElement& Elem)
   {
      Insert(Elem, Queue::End);
   }


   /* --- Remove the element first added to the queue. ---

      Return: Elem, the element first added to the queue
              The Queue containing this function, with Elem removed
   ----------------------------------------------------------------*/

   void Remove(ListElement& Elem)
   {
      assert(Length() != 0);
      Elem = First->Data;
      Delete(Queue::Beginning);
   }
};

#endif
