Skip to content

Commit ecfce5e

Browse files
committed
feat: add PriorityQueueDemo showing custom ordering using Comparator in PriorityQueue
Implemented PriorityQueueDemo.java to demonstrate reverse (max-heap) ordering via a user-defined Comparator. Highlights how PriorityQueue can be customized beyond natural ordering, using compare() logic to prioritize higher values. Includes peek(), poll(), and iteration to show heap behavior before and after deletion. Signed-off-by: https://github.com/Someshdiwan <[email protected]>
1 parent 32c6411 commit ecfce5e

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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)