How priority queue works | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How priority queue works

Priority queue works based on priority. And this priority has nothing to do with user, it is set internally by JVM.

6th Aug 2020, 12:28 PM
meghanamadhub 1003
meghanamadhub 1003 - avatar
4 Answers
6th Aug 2020, 12:45 PM
R๐Ÿ’ ๐Ÿ‡ฎ๐Ÿ‡ณ
R๐Ÿ’ ๐Ÿ‡ฎ๐Ÿ‡ณ - avatar
+ 5
A PriorityQueue is used when the objects are supposed to be processed based on the priority. It is known that a queue follows First-In-First-Out algorithm, but sometimes the elements of the queue are needed to be processed according to the priority, thatโ€™s when the PriorityQueue comes into play. The PriorityQueue is based on the priority heap. The elements of the priority queue are ordered according to the natural ordering, or by a Comparator provided at queue construction time, depending on which constructor is used. this will help u to understood the concepts of priority queue https://www.google.com/amp/s/www.geeksforgeeks.org/priority-queue-class-in-java-2/amp/
7th Aug 2020, 5:13 PM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 3
A priority queue is an abstract data type similar to regular queue or stack data structure in which each element additionally has a "priority" associated with it. In a priority queue, an element with high priority is served before an element with low priority. In some implementations, if two elements have the same priority, they are served according to the order in which they were enqueued, while in other implementations, ordering of elements with the same priority is undefined.
7th Aug 2020, 5:56 PM
Saurabh
Saurabh - avatar
- 1
Do any anyone know more about this. If yes plz share
6th Aug 2020, 12:28 PM
meghanamadhub 1003
meghanamadhub 1003 - avatar