Skip to content

Commit 17c26fc

Browse files
committed
feat: add PriorityQueueDemo1 demonstrating custom Comparator-based max-heap PriorityQueue
Implemented PriorityQueueDemo1.java to illustrate how PriorityQueue behavior can be customized using a user-defined Comparator. Demonstrates descending order (max-heap) prioritization with peek(), poll(), and iteration, showing element order before and after deletion. Signed-off-by: https://github.com/Someshdiwan <[email protected]>
1 parent ecfce5e commit 17c26fc

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

Section 25 Collections Frameworks/Queue Interface/Priority Queue/src/PriorityQueueDemo1.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import java.util.Comparator;
22
import java.util.PriorityQueue;
33

4-
class MyComp implements Comparator<Integer>
4+
class MyComp2 implements Comparator<Integer>
55
{
66
public int compare(Integer o1,Integer o2){
77
if(o1<o2)return 1;
@@ -15,7 +15,6 @@ public static void main(String[] args) {
1515

1616
PriorityQueue<Integer> PQ = new PriorityQueue<>(new MyComp());
1717

18-
1918
PQ.add(20);
2019
PQ.add(10);
2120
PQ.add(30);
@@ -33,4 +32,4 @@ public static void main(String[] args) {
3332

3433
PQ.forEach((x)-> System.out.print(" "+x));
3534
}
36-
}
35+
}

0 commit comments

Comments
 (0)