Let’s implement the circular queue using C++. Hence we can consume the entire space of the queue till it becomes full. We see that in the circular queue we move or insert elements in a circle. Next, we insert or enqueue element 11 in the circular queue as represented below.Īgain let us insert element 13 in the circular queue. item 1 and item 3 from the queue as shown below. When we insert the elements to make a queue full, the representation will be as shown below. In this section, we will go through a detailed illustration of adding/removing elements in the circular queue.Ĭonsider the following circular queue of 5 elements as shown below: If it is true then set front=rear= -1 else check if (front=size-1), if it is true then set front=0 and return the element. If queue is not empty then perform step 3. #2) If it is empty then display the message “Queue is empty”. #1) Check if the circular queue is Empty: check if (front=-1). Given below is the sequence for dequeue operation in a circular queue. In the circular queue, the element is always deleted from the front end. If it is true then set rear=0 and insert element.ĭequeue: Dequeue function is used to delete an element from the queue.
If queue is not full then, check if (rear = SIZE – 1 & front != 0). #2) If the circular queue is full then it displays a message as “Queue is full”. #1) Check if the circular queue is full: test ((rear = SIZE-1 & front = 0) || (rear = front-1)), where ‘SIZE’ is the size of the circular queue. We follow the following sequence of steps to insert a new element in the circular queue. The element is always inserted at the rear end of the queue. Rear: Returns the rear position in the circular queue.Įnqueue: Enqueue (value) is used to insert an element in the circular queue. Some of the basic operations of the circular queue are as follows:įront: Returns the front position in the circular queue. Using Array In this representation, an array is declared with N number of elements capacity and 2 indices FRONT and. In the next section, we will learn about the basic operations of the circular queue. The queue can be created using below 2 data structures.: 1. In the circular queue, when the queue is full, and when we remove elements from the front since last and first positions are connected, we can insert the elements at the rear which was vacated by deleting the element.
In a linear queue after the queue is full, we delete the elements from another end, and the status of the queue is still shown as full and we cannot insert more elements.
Due to this arrangement, space doesn’t go wasted as it happens in a linear queue. The first six elements are already in the queue and we see that the first position and last position are joined. The above image shows a circular data structure of size 10. If you would like to contribute, you can also mail your article to Please suggest your improvement for this article if you find anything incorrect.The following diagram shows a circular queue.
People waiting in line at the bank queue counter from a queue. In the Collection Interface, the Queue is already implemented for. As we know, Java had an already built-in Interface called Collection. In this post, we will learn about the Queue implementation in Java. But it stores the elements in FIFO (First In First Out) manner. Queues are sometimes referred to as First In First Out (FIFO) list. Same as Stack, Queue is a linear Data Structure. Queue is an ordered list in which all insertions at one end called REAR and deletions are made at another end called FRONT.