We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent ce373ff commit 20ec976Copy full SHA for 20ec976
1 file changed
Linear_Data_Structures/02_Queue/PriorityQueueExample.java
@@ -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