previous | index | next

Calculating an Enqueued Item's Location

Suppose that after more dequeues and enqueues, the queue looks like this:

Suppose a new item needs to be enqueued. To calculate its location, use the invariant:

     (start + i) mod cells_length =
     (start + queue_length) mod cells_length =
     (7 + 4) mod 8 =
     11 mod 8 =
     3

previous | index | next