
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 6710 Articles for Javascript

389 Views
In JavaScript, there is no such data structure concept as a Queue like other programming languages. But you can implement a queue in JavaScript using an array object. You can perform all the operations such as push() method to add element at end and shift() to remove first element. The following diagram will give a clear understanding of the queue data structure and its principles (FIFO): A Queue is a linear data structure that follows the FIFO (First In, First Out) principle. In JavaScript, it is used to store and manage elements of similar or different types. Here is ... Read More

717 Views
Though Arrays in JavaScript provide all the functionality of a Queue, let us implement our own Queue class. Our class will have the following functions − enqueue(element): Function to add an element in the queue. dequeue(): Function that removes an element from the queue. peek(): Returns the element from the front of the queue. isFull(): Checks if we reached the element limit on the queue. isEmpty(): checks if the queue is empty. clear(): Remove all elements. display(): display all contents of the arrayLet's start by defining a simple class with a constructor that takes the max size of the queue and a helper function that'll help us ... Read More

613 Views
In this article, we are going to discuss the queue data structure in JavaScript. It is a linear data structure where the enqueue and dequeue of elements follow the FIFO (first in first out sequence). The queue is open at both ends. One end is always used to insert data and the other is used to remove data. Here, we use two pointers rear and front. The rear is used to insert the data and the front is used to remove the data. A real-world example of the queue can be a single-lane one-way road, where the vehicle enters first, ... Read More

232 Views
Here is the complete implementation of the Stack class −Exampleclass Stack { constructor(maxSize) { // Set default max size if not provided if (isNaN(maxSize)) { maxSize = 10; } this.maxSize = maxSize; // Init an array that'll contain the stack values. this.container = []; } display() { console.log(this.container); } isEmpty() { return this.container.length === 0; } isFull() { return this.container.length >= this.maxSize; } ... Read More

965 Views
Consider a simple stack class in Javascript. Exampleclass Stack { constructor(maxSize) { // Set default max size if not provided if (isNaN(maxSize)) { maxSize = 10; } this.maxSize = maxSize; // Init an array that'll contain the stack values. this.container = []; } // A method just to see the contents while we develop this class display() { console.log(this.container); } // Checking if the array is empty isEmpty() { ... Read More

759 Views
Consider a simple stack class in Javascript. Exampleclass Stack { constructor(maxSize) { // Set default max size if not provided if (isNaN(maxSize)) { maxSize = 10; } this.maxSize = maxSize; // Init an array that'll contain the stack values. this.container = []; } // A method just to see the contents while we develop this class display() { console.log(this.container); } // Checking if the array is empty isEmpty() { ... Read More

300 Views
Consider a simple stack class in Javascript.Exampleclass Stack { constructor(maxSize) { // Set default max size if not provided if (isNaN(maxSize)) { maxSize = 10; } this.maxSize = maxSize; // Init an array that'll contain the stack values. this.container = []; } // A method just to see the contents while we develop this class display() { console.log(this.container); } // Checking if the array is empty isEmpty() { ... Read More

261 Views
Consider the following stack class in Javascript with few small helper functions.Exampleclass Stack { constructor(maxSize) { // Set default max size if not provided if (isNaN(maxSize)) { maxSize = 10; } this.maxSize = maxSize; // Init an array that'll contain the stack values. this.container = []; } // A method just to see the contents while we develop this class display() { console.log(this.container); } // Checking if the array is ... Read More

2K+ Views
In this article, we are going to discuss how to create the stack data structure in JavaScript. It is a linear data structure where the push and popping of elements follow the LIFO (last in first out and FILO (first in last out) sequence. Though Arrays in JavaScript provide all the functionality of a Stack, let us implement our own Stack class. Our class will have the following functions. push(element) − Function to push elements on top of the stack. pop() − Function that removes an element from the top and returns it. peek() − Returns the element on ... Read More

842 Views
In this article, we are going to discuss the stack data structure in JavaScript. A stack is an Abstract Data Type (ADT), commonly used in most programming languages. It is named stack as it behaves like a real-world stack, for example – a deck of cards or a pile of plates, etc. A stack allows operations at one end only. This feature makes it LIFO data structure. LIFO stands for Last-in-first-out. Here, the element which is placed (inserted or added) last, is accessed first. In stack terminology, insertion operation is called PUSH operation and removal operation is called POP ... Read More