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?


  • 1
    $\begingroup$ 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. $\endgroup$
    – jboockmann
    Jul 7, 2018 at 11:11

1 Answer 1


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}$.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.