Understanding basic queue and dequeue operations
CLRS defines a queue using an array which wraps around i.e when we no longer can insert/delete in the last position, we move to the first position.

From the book,


  The elements in the queue are in locations head[Q], head [Q] + 1, . . . , tail [Q] - 1, where we "wrap around" in the sense that location 1 immediately follows location n in a circular order. 


Thus, 


  if Q.tail == Q.length


This is for the condition when the tail points to the last element. 


  if Q.head == Q.length


This is for the condition when the head points to the last element.

In both cases, we move to the first element due to circular nature.

An example would be this: