The Queue is a Data Structure, supports the insertion and deletion of elements in particular order, i.e, FIFO (First In First Out). Whenever an element is inserted it goes to the top of the queue and the element which is inserted at the last (element at the top of the queue) will be removed at first.

Note: Unlike stack in a queue, we maintain two pointers: *head* and *rear*.

*1. head* pointer point to the start of the queue.

*2. rear* pointer points to the last element of the queue.

**Basic Queue Operation:**

**Enqueue:** Enqueue operation inserts an element at the rear of the queue. Every time an element is inserted, the rear pointer is incremented.

*Enqueue(var):*

* If(rear == maxsize)*

* print “queue is full”*

* else*

* queue[rear] = var*

* rear++*

**Dequeue:** Dequeue operation deletes an element from the front of the queue. Every time an element is deleted, the front pointer is incremented. If the front becomes equal to the rear, then the queue is empty.

Algorithm:

*Dequeue():*

* If(front == rear)*

* print “queue is empty”*

* else*

* var = queue[front]*

* queue[front] = 0*

* front –;*

* return var;*

**Time Complexity Of Stack Operation**

- Enqueue Operation: O(1)
- Dequeue Operation: O(1)
- Search an Element: O(N)

**Implementation of Queue Data Structure in CPP**

*Output:*

*Queue content is:*

*1 5 7 9 10 12 *

*Queue content is:*

*7 9 10 12 *

*Queue content is:*

*7 9 10 12 15*