Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

Implementation Using Heap

Output of above implementation:-

Default Max PQ in Java

In Java 8+ you can create a max priority queue via one of these methods:

Method 1:

PriorityQueue<Integer> maxPQ = new PriorityQueue<>(Collections.reverseOrder());

Method 2:

PriorityQueue<Integer> maxPQ = new PriorityQueue<>((a,b) -> b - a); 

Method 3:

PriorityQueue<Integer> maxPQ = new PriorityQueue<>((a,b) -> b.compareTo(a));

NOTE: Implementation ()s of priority Queue is totally same as heap DS function which is covered in heap DS.

Priority Queue --------- Heap

  1. add() = minInsert()
  2. peek() = getMin()
  3. remove() = extractMin()