- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Samual Sam has Published 2492 Articles
Samual Sam
590 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 ... Read More
Samual Sam
663 Views
Dequeuing elements from a Queue means removing them from the front/head of the queue. We are taking the start of the container array to be the head of the queue as we'll perform all operations with respect to it.Hence, we can implement the pop function as follows − Exampledequeue() { ... Read More
Samual Sam
242 Views
We can clear the contents just by reassigning the container element to an empty array. For example, clear() { this.container = []; }ExampleYou can check if this function is working fine using:let q = new Queue(2); q.enqueue(3); q.enqueue(4); q.display(); q.clear(); q.display();OutputThis will give the output:[ 3, 4 ] [ ]
Samual Sam
124 Views
Enqueuing elements to a PriorityQueue means adding them in the array in order of the priority of the element. We'll consider higher numbers to be higher priorities. We'll loop through the container till we find a lower priority and then add the element there. If not, then we'll push it ... Read More
Samual Sam
184 Views
The do...while loop is similar to the while loop except that the condition check happens at the end of the loop. This means that the loop will always be executed at least once, even if the condition is false.For example, Examplelet i = 0; do { console.log("Hello"); i ... Read More
Samual Sam
189 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 = ... Read More
Samual Sam
454 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 ... Read More
Samual Sam
145 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 ... Read More
Samual Sam
230 Views
Basically, multi-dimension arrays are used if you want to put arrays inside an array. Let's take an example. Say you wanted to store every 6 hour's temperature for every weekday. You could do something like −let monday = [35, 28, 29, 31]; let tuesday = [33, 24, 25, 29]; //...This ... Read More
Samual Sam
303 Views
The array is a container which can hold a fixed number of items and these items should be of the same type. It stores a fixed-size sequential collection of elements of the same type. An array is used to store a collection of data, but it is often more useful ... Read More