Intro to Queues

Jaskomal
2 min readJul 19, 2021

In this article I will give a brief overview over the data structure that is the Queues. Like their name implies a queue is essentially a line that is made up of data nodes, the data moves in a linear fashion with whatever is at the head going first, and new data being added to the end. Often queues are used with singly linked lists. There are three methods we use in interacting with queues, Enqueue is when we add data to the back of the queue. Dequeue is removes data from the front of the queue, and peek shows the data that is at the front of the queue without removing it.

With queues we only interact with the first or the last element, so since we often use this with linked lists, queues will interact with the head element or the tail element. So when we place a linked list into a queue we will not be able to interact with middle elements, until that element reaches the front of the queue. Another restriction to consider when working with a queue is to see if the queue has a limit also known as a bounded queue, if it does then the excess data will be put into a queue overflow. On the opposite side a empty queue is called a queue underflow.

function Queue() {          this.elements = []; }Queue.prototype.enqueue = function (e) {    this.elements.push(e); };// remove an element from the front of the queue Queue.prototype.dequeue = function () 
{
return this.elements.shift();
};

--

--