![]() |
A priority queue is a specialized type of queue, in which elements are given with priorities, and those with more priorities are served before elements with lower priorities. It’s equivalent to a regular queue (first-in, first-out) but prioritizes urgency rather than arrival order. Remove the Top Element from a PriorityQueueIn Java, we can remove the top element (element with the highest priority) from a PriorityQueue using the poll() method. This method removes and returns the highest priority element from the queue. Syntax:public E poll()
Program to Remove the Top Element(highest priority) From a PriorityQueueHere is the implementation: Java
Output
PriorityQueue before removal: [1, 10, 5, 20] Removed element: 1 PriorityQueue after removal: [5, 10, 20] Explaination of the above Program:
|
Reffered: https://www.geeksforgeeks.org
Java |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 13 |