title: I don't quite understand this algorithm on queue
body: <p>Here's the queue using array implementation in Robert Sedgewick's book:</p>
  
  <pre><code>class QUEUE {
  private:
      int* q;
      int N;
      int head;
      int tail;
  public:
      QUEUE(int maxN) {
          q = new int[maxN + 1];
          N = maxN + 1; head = N; tail = 0;
      }
      int empty() const {
          return head % N == tail;
      }
      void put(int item) {
          q[tail++] = item; tail = tail % N;
      }
      int get() {
          head = head % N; return q[head++];
      }
  };
  </code></pre>
  
  <p>My concern is about the <code>get()</code> method.
  Consider the size to be 10;
  According to the code, initially, the index of head = 11 and index of tail  = 0.</p>
  
  <p>Now, add an element, say 1. So, 1 is placed in the index position 0 and the tail position is incremented to 1.
  Now add another say 5. 5 is at index pos 1 and the tail now is index 2.</p>
  
  <p>Now use the get() function, which does: <code>return q[head++];</code> which is to return the element at head and then increment the head but BOOOOOM!!!!! The head is index no 11 as we have just seen and it has no value stored in it and this must be a huge error. But, this code is correct as it's Robert Sedgewick and we are the one's mistaken. What's going on guys? :(</p>