-
Notifications
You must be signed in to change notification settings - Fork 79
Expand file tree
/
Copy pathPriorityQueueTest.java
More file actions
27 lines (24 loc) · 923 Bytes
/
Copy pathPriorityQueueTest.java
File metadata and controls
27 lines (24 loc) · 923 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
27
package priorityQueue;
import java.util.*;
/**
* This program demonstrates the use of a priority queue.
* @version 1.01 2012-01-26
* @author Cay Horstmann
*/
public class PriorityQueueTest
{
public static void main(String[] args)
{
PriorityQueue<GregorianCalendar> pq = new PriorityQueue<>();
pq.add(new GregorianCalendar(1906, Calendar.DECEMBER, 9)); // G. Hopper
pq.add(new GregorianCalendar(1815, Calendar.DECEMBER, 10)); // A. Lovelace
pq.add(new GregorianCalendar(1903, Calendar.DECEMBER, 3)); // J. von Neumann
pq.add(new GregorianCalendar(1910, Calendar.JUNE, 22)); // K. Zuse
System.out.println("Iterating over elements...");
for (GregorianCalendar date : pq)
System.out.println(date.get(Calendar.YEAR));
System.out.println("Removing elements...");
while (!pq.isEmpty())
System.out.println(pq.remove().get(Calendar.YEAR));
}
}