It’s very-well-known tip for cyclic queue!
Here is pseudo code!
(Even if this is very -well-known and not difficult to think of, it’s worth to remind.)
TYPE Q item[SZ] // queue array i // current index ... FUNC addQ (q, item) // This is Naive way. item[q.i] = item if (q.i >= SZ) than q.i = 0 // This is well-known way item[q.i] = item q.i &= SZ-1 // For this, SZ should be (2^n (n>0))