Data Structure: Never Forget About A Queue

We see the concept of a queue in our day-to-day life.

Arnish Gupta
2 min readAug 16, 2020

When we go to the reservation counter to book a ticket or bank to deposit the cash, So when we enter the line and we stand at the end of the line, and the person who is at the front of the line is served first. After that, the next person will come at the head of the line and exit from the queue. This process keeps working and finally, we will reach the head of the line and we will exit the query and be served.

Photo by Adrien Delforge on Unsplash

What is a Queue: A queue is a data structure used for storing data (similar Stack). A queue is a line of people or things waiting to be served in sequential order starting at the beginning of the line.

A queue is an ordered list in which insertion are done at one end (rear) and deletions are done at other end (front). The first element to be inserted is the first one to be deleted. So we can also called FIFO (First in First out) List.

Some special things in a queue are, When an element is inserted in a queue, we called EnQueue, and the same with when an element deleted in a queue called DeQueue. When we do Dequeueing the data from an empty queue is called UnderFlow and EnQueueing the data on the full queue is called OverFlow.

Queue Operations:

  • void enQueue(int data): Inserts an element at the end of the queue.
  • int deQueue(): Remove an element at the front of the queue and return removed element.
  • int front(): return front of the queue data.
  • int queueSize(): return total number of the queue.
  • boolean isEmptyQueue(): return the queue is empty or not.

Implementation: There are many ways of implementing queue operations. Let’s look some ways:

  • Simple Array Based Implementation.
  • Dynamic Array Based Implementation.
  • Linked List Implementation.

Simple Array Based Implementation: Here we will create a simple array and we write the definition of all queue operation.

Dynamic Array Based Implementation: We have some limitation in static array that is we have fixed sized of array. Let’s solve the problem by using dynamic array. Here we will use expand() method for increase the size of the queue when queue is full.

Linked List Implementation: Let’ do this by linked list style.

That’s it. I hope it will help you to understand a queue. I will work on another article about the solutions of the problem by using a queue. Stay tune with my article.

Clap for me if you feel good about your knowledge.

Thank you for reading.

Happy Happy !!

--

--

Arnish Gupta

Learn Blockchain with me every Monday at 9AM (GMT+5:30).