In our procedures ENQUEUE and DEQUEUE, the error checking for underflow and overflow has been omitted. (Exercise 10.1-4 asks you to supply code that checks for these two error conditions.)
ENQUEUE(Q, x) 1 Q[tail[Q]] ← x 2 if tail[Q] = length[Q] 3 then tail[Q] ← 1 4 else tail[Q] ← tail[Q] 1 DEQUEUE(Q) 1 x ← Q[head[Q]] 2 if head[Q] = length[Q] 3 then head[Q] ← 1 4 else head[Q] ← head[Q] 1 5 return x
Figure 10.2 shows the effects of the ENQUEUE and DEQUEUE operations. Each operation takes O(1) time.