# Circular queue problem

In ciruclar queue the following command statement is very useful to use the determine the unused location. What is its importance? I know that without this line it won't be a circular queue. But how to say it in theoretical way?

### rear=(rear+1)%max

• the modulus operation ensures that the new value of rear will always be greater equals 0 and smaller than max. Hence, you will neve get out of bound errors and instead continue at 0 once you have reached the end. – jboockmann Jul 7 '18 at 11:11

Suppose that we arrange the numbers $0,\ldots,n-1$ in an oriented cycle. The number which follows $i$ is $i+1$ for $i \neq n-1$, and $0$ for $i=n-1$. We can combine both cases by saying that the number following $i$ is $i+1 \bmod{n}$.