-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpqueue.java
More file actions
26 lines (25 loc) · 883 Bytes
/
pqueue.java
File metadata and controls
26 lines (25 loc) · 883 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import java.util.*;
class pqueue {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
PriorityQueue queue = new PriorityQueue();
queue.add("Amit");
queue.add("Vijay");
queue.add("Jay");
queue.add("Raj");
System.out.println("Priority Queue: " + queue);
System.out.println("Head: " + queue.peek());
System.out.println("Iterating the queue elements: ");
Iterator itr = queue.iterator();
while (itr.hasNext()) {
System.out.println(itr.next());
}
System.out.println("After first removal");
queue.remove();
System.out.println(queue);
// to remove all elements from the queue
queue.poll();
System.out.println("After second removal:");
System.out.println(queue);
}
}