## What is Queue?

Queue is a linier Data Structure in which insertion operation is performed at one end called Rear and deletion operation is performed at another end called front.

Since insertion operation is performed at rear end and deletion operation is performed at front end the element which is inserted first is first to delete. So Queue is also known as First in First out (FIFO).
Consider a Queue of Students at Fee Counter waiting to pay fee. The students pay fee in the same order as they are standing in the queue. The students who stand first in the Queue pay the fees first and come out from the queue.

## Operations Performed on Queue

There are two main operations that can be performed on Queue.

## Insert Operation

Insert operation is used to insert an element into Queue.
In order to insert an element into Queue first we have to check weather space is available in the Queue or not. If Queue is full then we can not insert an element into Queue. If value of REAR variable is greater then or equal to SIZE – 1 then we can not insert an element into Queue. This condition is known as “Overflow”.
If Queue is not overflow then we can insert an element into Queue. First we have to increment the value of REAR variable by one and then insert an element into Queue.
If the element which is inserted in Queue is first element then we have to set the value of FRONT variable to 0.

Step 1: If REAR >= SIZE – 1 then
Write “Queue is Overflow”
Step 2: REAR = REAR + 1
Step 3: QUEUE [REAR] = X
Step 4: If FRONT = -1 then
FRONT = 0

## Delete Operation

Delete operation is used to delete an element from Queue.
In order to delete an element from Queue first we have to check weather Queue is empty or not. If Queue is empty then we can not delete an element from Queue. This condition is known as “Underflow”.
If Queue is not underflow then we can delete element from Queue. After deleting element from Queue we have to set the value of FRONT and REAR variables according to the elements in the Queue.

Step 1: If FRONT = -1 then
Write “Queue is Underflow”
Step 2: Return QUEUE [FRONT]
Step 3: If FRONT = REAR then
FRONT = 0
REAR = 0
Else
FRONT = FRONT + 1