Circular queues
At the end of this chapter, let’s take a look at another data structure, namely a circular queue, also called a ring buffer. In this case, a queue forms a circle, internally uses an array, and the maximum number of elements that can be placed inside the queue is limited. You need to specify two variables that indicate indices of the front and rear elements. The front one points to the element that will be dequeued first. The rear one points to the element that is the last in the queue.
Imagine a circular queue
If you want to better imagine a circular queue, think back to your young years when you persuaded your parents to take you on a roller coaster. It consisted of 10 carriages, each with room for 2 people, so only 20 people could take part in 1 roller coaster ride. As this was a unique attraction, such a ride took place only once an hour. This meant that only 20 people were allowed to enter a queue for the roller coaster and no one else. As the departure...