## DEV Community # Introduction to Data Structures and Algorithms with Modern JavaScript

## Arrays

In JavaScript, an array is a variable that stores several elements.Arrays are used when we want store a list of elements and retrieve them with single variable.
In modern JS, an array may hold different data types such as strings, numbers, boolean. All this can be stored in one array. Elements in arrays are denoted by index and therefore the first element of an array is always denoted with the  index.
Below is an illustration:

``````arr = ["lux","Alvin", "academy"]
``````

Hence the element lux is in index 0, element Alvin is in index 1 and the element academy is index 2.

## Stack

It is one of the important data structures and a useful one, with a wide range of applications. It is a linear data structure where by any addition or deletion of an element follows a particular order i.e Last in Fast Out (LIFO) and Fast in Last Out (FIFO).

An example of its implementation is as below:

``````// Adding element to the stack
stack.push(10);
stack.push(20);
stack.push(30);

// Printing the stack element
// prints [10, 20, 30]
console.log(stack.printStack());

// returns 30
console.log(stack.peek());

// returns 30 and remove it from stack
console.log(stack.pop());

//returns [10, 20]
console.log(stack.printStack());

``````

## Queue

Unlike stack, Queue works on the First in First Out (FIFO) principle. Queue performs two basic operations i.e additional of elements at the end of the queue and removal of elements at the front of the queue. It is also a linear data structure. Queue contains functions such as enqueue, dequeue, front(), and is Empty().
An illustration of how the enqueue and dequeue function is as below:

``````// enqueue function
enqueue(element)
{
// adding element to the queue
this.items.push(element);
}

``````

//dequeue

``````// dequeue function
dequeue()
{
// removing element from the queue
// returns underflow when called
// on empty queue
if(this.isEmpty())
return "Underflow";
return this.items.shift();
}

``````

For moreinformation on how Queue works visit [https://www.geeksforgeeks.org/implementation-queue-javascript/].

````const list = { head: { value: 6 next: { value: 10 next: { value: 12 next: { value: 3 next: null } } } } } };```