previous | index | next

A Suboptimal Queue Representation

Suppose we use the same header and cells two-vector approach we used for stacks:

Here, 5 is the oldest element (head) and 1 is the newest (tail).

And suppose we maintain the following representation invariant:

The head of the queue is in cell number 0 and the remaining elements follow in consecutive cells.

Q: Why is this approach not optimal?

A:


previous | index | next