queue-in-datastructure

QUEUE: What is a queue in data structure?

I am going to discuss the queue in this blog post. A queue is also known as a non-primitive linear data structure. In this queue, the element is grouped in order.

Here in the queue, the element is added at one end that is called rear end and the existing elements are removed from another end that is called front end.

In below Fig1 you can see a queue containing three elements A, B, C. A is placed at the front of the queue and C is placed at the rear end.

queue-operation
QUEUE

In Fig2 an element has been deleted from the queue and since element can be deleted only from the front end of the queue, A is removed and B is at the front now.

In Fig3 when we are supposed to insert new item D and E then they must be inserted at the rear end of the queue. Since we inserted D before E than at the time of removal D will be first to remove from the queue. We can also conclude that the first element inserted in the queue will be the first element to be removed from the queue.

Because of the inserting and removing procedure, it is also named as FIFO(first in first out) list. you can also understand the scenario with a real-life example like a line at the bank cash counter to withdraw money. One who will come first will go first or will be served first.

Initializing a queue will be the first process to work with a queue. Adding an element to the queue and deleting an element to the queue are the other operation of the queue.

Adding an element to the queue is also known as ENQ, whereas deleting an element to the queue is known as DEQ, these are the popular name given to these operations. Few more popular operation of the queue is given below.

QUEUE OPERATIONS

CREATE(Q): This is used to create an empty queue.

ENQ(i): This is used to add a new element i to the rear of the queue and return a new queue.

DEQ(Q): This is used to remove the element at the front end of the queue and return the new result queue along with the removed element.

EMPTY(Q): It is used for checking whether a queue is empty or not. If the queue is empty then returns true else false.

FRONT(Q): it returns the front end of the queue without any change in the queue.

QUEUESIZE(Q): It tells us the total number of entries in the queue.