What is queue data structure? Javascript

Hi, a data structure is a way of organizing information with optimal runtime complexity for adding or removing records.

Javascript natively implements several data structures like arrays, queue, etc. and most of the time we need to select the correct data structure according to the problem necessity. 

Let see the data structure called Queue

A queue can be like a container source where pieces of data enter into the queue and exit on the other side 

We can think in the queue as a line that is waiting in line for buy tickets in the movie theater.

In this example you can image that the line of people waiting to get to the ticket counter is very much like a queue because a person will enter into the line at the very end then they have to wait in the line until is their turn to emerge from it and approach to ticket counter. 

In a queue there is not idea of skipping or cutting in line so the order in which you get into the queue also dictates the order which you come out.

The process of adding a record into the queue is called as “Enqueuing or adding”

The process to taken a record from the other side of the queue is called “Dequeuing or removing”

A queue refers to “FIFO” that means First In First Out.

If we want to implement a queue in javascript basically we need to implement an array and use some methods like array.unshift(); to add element to the very front in the array (queue) and array.pop() to remove elements from the queue. 

We will implement a queue in the next post.

By Cristina Rojas.