title: Implementing Circular Array Queue
body: <p>I am to implement a Circular Array Queue But I a having logical errors and I  am not getting the correct result. I need help implementing bool dequeue() in ArrayQueueP4.h. I doubt if it is correct.</p>
  
  <p>.</p>
  
  <p>I have tried different solutions as well as search through previous questions on stack overflow and online yet it did not give me any ideas on what I am looking for</p>
  
  <pre><code>#ifndef ARRAY_QUEUE_P4_
  #define ARRAY_QUEUE_P4_
  #include "QueueInterface.h"
  #include "PrecondViolatedExcept.h"
  
  template&lt;class ItemType&gt;
  class ArrayQueueP4 : public QueueInterface&lt;ItemType&gt;
  {
  private:
      static const int DEFAULT_CAPACITY = 50;
      ItemType items[DEFAULT_CAPACITY + 1]; // Array of queue items
      int front;                   // Index to front of queue
      int back;                    // Index to back of queue
  
  public:
      ArrayQueueP4() : front(DEFAULT_CAPACITY),
          back(DEFAULT_CAPACITY) {};
      // Copy constructor and destructor supplied by compiler
      bool isEmpty() const;
      bool enqueue(const ItemType&amp; newEntry);
      bool dequeue();
  
      /** @throw  PrecondViolatedExcept if queue is empty. */
      ItemType peekFront() const;
  };
  
  ArrayQueueP4.h is the header file for ArrayQueueP4.cpp
  #include "ArrayQueueP4.h";
  
  #include "PrecondViolatedExcept.h";
  
  using namespace std;
  
  template &lt;class ItemType&gt;
  bool ArrayQueueP4 &lt;ItemType&gt;::isEmpty() const {
      return (front == back);
  }
  
  template &lt;class ItemType&gt;
  bool ArrayQueueP4 &lt;ItemType&gt;::enqueue(const ItemType&amp; newEntry) {
  
      if (!isEmpty())
  
      back = (back + 1) % DEFAULT_CAPACITY;
      items[back] = newEntry;
      back++;
      return true;
  
  
  }
  
  template&lt;class ItemType&gt;
  bool ArrayQueueP4 &lt;ItemType&gt; ::dequeue() {
      bool result = false;
      if (!isEmpty()) {
          front = (front + 1) % DEFAULT_CAPACITY;
          front--;
          result = true;
      }
      return result;
  }
  
  template&lt;class ItemType&gt;
  ItemType ArrayQueueP4&lt;ItemType&gt;::peekFront() const {
  
      if (isEmpty())
          throw PrecondViolatedExcept("peekFront() called with an empty queue.");
      else
          return items[front];
  
  }
  
  HERE is my main file main.cpp to test my code
  
  
  #include &lt;iostream&gt;
  
  #include "ArrayQueueP4.cpp";
  
  using namespace std;
  
  int main() {
      ArrayQueueP4&lt;int&gt; AP;
      AP.enqueue(1);
      AP.enqueue(2);
      AP.enqueue(3);
  
      /*LinkedQueueP1&lt;int&gt; LP;
      LP.enqueue(1);
      LP.enqueue(2);*/
  
      cout &lt;&lt; "PEEK FRONT: " &lt;&lt; AP.peekFront();
      //cout &lt;&lt; "PEEK FRONT: " &lt;&lt; LP.peekFront();
  
      system("pause");
      return 0;
  }
  </code></pre>
  
  <p>Based on my main program file, the output supposed to now 1 when I call the enqueue function. But instead of getting 2 as my answer, I am getting -858993460 as my result when I delete the first item using dequeue(). I do not know if that is how Queues behave but isn't the second number supposed to be the next first item in line when I delete the first number?</p>