Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

min max heap java

// min heap: PriorityQueue implementation from the JDK
PriorityQueue<Integer> prq = new PriorityQueue<>();

// max heap: PriorityQueue implementation WITH CUSTOM COMPARATOR PASSED
// Method 1: Using Collections (recommended)
PriorityQueue<Integer> prq = new PriorityQueue<>(Collections.reverseOrder());
// Method 2: Using Lambda function (may cause Integer Overflow)
PriorityQueue<Integer> prq = new PriorityQueue<>((a, b) -> b - a);
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #min #max #heap #java
ADD COMMENT
Topic
Name
2+8 =