2

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

Kalana Mihiranga
  • 234
  • 2
  • 12

1 Answers1

6

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

Yuval Filmus
  • 280,205
  • 27
  • 317
  • 514