A circular queue, also known as a circular buffer, is a data structure that represents a collection of elements in a circular manner. in a circular queue, the last element follows the first element, forming a circle. The primary advantage of a circular queue over a standard queue is that it allows for efficient use of memory, as the elements are stored in a fixed-size array.
The following are the key components of a circular queue:
front
and rear
pointers: The front
pointer is the index of the first element in the queue, and the rear
pointer is the index of the last element in the queue.array
that the elements of the queue are stored.The operations that can be performed on a circular queue are:
addq
: This operation adds an element to the rear+1
of the queue, It may vary depending on how you design the circular queue. If the queue is not full, the rear pointer is incremented, and the element is added to the new rear index. If the rear pointer reaches the end of the array, it wraps around to the beginning.deleteq
: This operation removes the element from the front+1
of the queue. If the queue is not empty, the front pointer is incremented, and the element is removed from the old front index. If the front pointer reaches the end of the array, it wraps around to the beginning.queueFull
: This operation notifies you of the certain message if the queue is full.queueEmpty
: This operation notifies you of the certain message if the queue is empty.