- 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
Remove elements from a PriorityQueue using Javascript
Dequeuing elements from a PriorityQueue means removing the element of the highest priority. We are storing the elements with the highest priority at the end of the array, we can simply pop it to dequeue it.
Hence, we can implement the dequeue function as follows −
Example
dequeue() { // Check if empty if (this.isEmpty()) { console.log("Queue Underflow!"); return; } return this.container.pop(); }
You can check if this function is working fine using
let q = new PriorityQueue(4); q.enqueue("Hello", 3); q.enqueue("World", 2); q.enqueue("Foo", 8); console.log(q.dequeue()); q.display();
Output
This will give the output −
{ data: 'Foo', priority: 8 } [ { data: 'World', priority: 2 }, { data: 'Hello', priority: 3 }]
- Related Articles
- Peeking elements from a PriorityQueue using JavaScript
- Add elements to a PriorityQueue using Javascript
- Clearing the elements of the PriorityQueue using Javascript
- Remove elements from a queue using Javascript
- Remove elements from a Set using Javascript
- Remove elements from a Dictionary using Javascript
- Remove elements from a linked list using Javascript
- Remove elements from array using JavaScript filter - JavaScript
- Remove elements from array in JavaScript using includes() and splice()?
- Remove elements from Javascript Hash Table
- Remove elements from singly linked list in JavaScript
- How to remove blank (undefined) elements from JavaScript array - JavaScript
- The PriorityQueue Class in Javascript
- How to remove all the elements from a set in javascript?
- How to remove all the elements from a map in JavaScript?

Advertisements