Skip to content

Commit 20ec976

Browse files
authored
Create PriorityQueueExample.java
1 parent ce373ff commit 20ec976

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Author: Aayush Raj
2+
// Description: Demonstrates Priority Queue in Java using java.util.PriorityQueue
3+
4+
import java.util.PriorityQueue;
5+
6+
public class PriorityQueueExample {
7+
public static void main(String[] args) {
8+
PriorityQueue<Integer> pq = new PriorityQueue<>();
9+
10+
pq.add(30); // lower = higher priority
11+
pq.add(10);
12+
pq.add(20);
13+
14+
System.out.println("🧾 Serving tasks by priority:");
15+
while (!pq.isEmpty()) {
16+
System.out.println("Processed: " + pq.poll());
17+
}
18+
}
19+
}
20+
21+
/*
22+
🖥️ Output:
23+
🧾 Serving tasks by priority:
24+
Processed: 10
25+
Processed: 20
26+
Processed: 30
27+
*/

0 commit comments

Comments
 (0)