Usually, circular queues are realized by finding the remainder logically. Assuming the size of the array is n, when the element subscript I increases 1, I = (I+ 1)% n is used to realize it.
Extended data:
Queues are characterized by first-in first-out or last-in first-out. Circular queue is called circular queue in data structure. That is, the tail and head of the queue are connected together to form a ring, so that when a false overflow occurs, the tail pointer can jump to the beginning of the array and reuse the memory cells that have been deleted from the queue.
You can use an array and two pointers (head pointer and tail pointer, but the data type can be an integer, just indicating the meaning of pointing) to form a structure to realize the queue.
Circular queue is a program that can realize all structures and improve personal understanding of pointers.
The program was written in codeblock, and one problem after another was encountered in the middle, which was finally solved. This structure can be used as a model for all structures. Writing these programs can make you understand the pointer more deeply and be more familiar with its various uses.
Baidu encyclopedia-circular queue