title: Queue implementation and array resizing using C++
body: <p>The code is supposed to do queue functions which I got right.</p>
  
  <p>The only problem I am having is: I am supposed to double the array size to twice its original size once the array gets completely filled.</p>
  
  <p>I have coded for it but still getting garbage values when I try to put in more values than the original array size. So the problem seems to be in the inc() function below:</p>
  
  <pre><code>#ifndef Q_H_
  #define Q_H_
  
  #include &lt;iostream&gt;
  using namespace std;
  
  
  
  template &lt;class elemType&gt;
  class arrayQueue
  {
      int size;
      int *array;
      int front;
      int back;
      int count;
  
  public:
      arrayQueue(elemType size)
  {
          this-&gt;size = size;
          array = new int[size];
          front = 0;
          back = -1;
          count=0;
  }
  
      bool isEmpty()
      {
          return (max()==0);
      }
  
      bool isFull() {
          return (max()==size);
      }
  
      void enqueue(elemType entry)
      {
          cout &lt;&lt; "enqueue " &lt;&lt; entry;
  
          if(isEmpty())
          {
              front = back = 0;
              array[back] = entry;
              count++;
          }
          else
          {
              back = (back+1) % size;
              array[back] = entry;
              count++;
          }
          cout &lt;&lt; endl;
      }
  
      int maxsize()
      {
          return count;
      }
  
      void dequeue() {
          cout &lt;&lt; "dequeue : " &lt;&lt; Front();
          if(isEmpty())
          {
              cout &lt;&lt; " error : empty";
          }
          else if(back == front)
          {
              back = front = -1;
          }
          else
          {
              front = (front+1) % size;
              count--;
          }
          cout &lt;&lt; endl;
      }
  
      void print()
      {
          if(isEmpty())
          {
              cout &lt;&lt; "Queue is empty";
          }
          else
          {
              for(int i = front; i&lt;count; i++)
              {
                  cout &lt;&lt; array[i] &lt;&lt; " ";
              }
              cout &lt;&lt; array[back];
  
          }
          //cout&lt;&lt;"count is:" &lt;&lt;count&lt;&lt;endl;
          cout &lt;&lt; endl;
      }
  
      int Front()
      {
  
          if(front == -1)
          {
              cout&lt;&lt;"Queue is empty\n";
              return -1;
          }
          return array[front];
  
      }
  
      int Back()
      {
          if(back==-1)
          {
              cout&lt;&lt;"Queue is full";
          }
          return array[back];
      }
  
      int max()
      {
          return count;
          cout &lt;&lt;"count: " &lt;&lt;count;
  
      }
  
      void inc()
      {
          int newsize = this-&gt;size*2;
  
          elemType *temp = new elemType[newsize];
  
  
  
          for (int i=0; i&lt;this-&gt;count;i++)
          {
              temp[i]=this-&gt;array[(front+i) % size];
          }
  
          delete [] this-&gt;array;
          this-&gt;array=temp;
          this-&gt;count=newsize;
  
  //      front=array[front];  //0
          //front = 0;
          //back=count;
  
  
      }
  
  
  };
  
  
  
  #endif /* Q_H_ */
  </code></pre>
  
  <p>I would really appreciate help with this.</p>