So far we've looked into the way of implementing a queue using few linear data structures, such as an array and LinkedList. But there's a small performance improvement still needed in the earlier implementations. If you observe closely the performance table described in the previous section, you can see that the dequeue operation of a queue takes an additional amount of time to rearrange the elements of the array. We can improve this by implementing a circular queue.
We can define a circular queue as a queue that maintains two indices in it (front and rear) for doing enqueue and dequeue operations. In this case, enqueue is not always adding an element at the last index. Similarly, dequeue is not always removing an element from 0th index.
The following snippet shows what the circular queue looks like:
class CircularFixedQueue<E> {
...