/** * CSE 373, Winter 2011, Jessica Miller * This program tests our PriorityQueue implementations. */ import java.awt.*; import java.io.*; import java.util.*; public class PriorityQueueTest { public static void main(String[] args) { testIntPriorityQueue(); System.out.println(); testPriorityQueueWithIntegers(); System.out.println(); testPriorityQueueWithStrings(); System.out.println(); testPriorityQueueWithPrintJobs(); } public static void testIntPriorityQueue() { IntPriorityQueue pq = new IntBinaryHeap(); pq.add(13); pq.add(20); pq.add(11); pq.add(44); pq.add(3); pq.add(7); pq.add(9); System.out.println(pq); System.out.println(pq.peek()); while (!pq.isEmpty()) { System.out.println(pq.remove()); System.out.println(pq); } } public static void testPriorityQueueWithIntegers() { PriorityQueue pq = new BinaryHeap(); pq.add(13); pq.add(20); pq.add(11); pq.add(44); pq.add(3); pq.add(7); pq.add(9); System.out.println(pq); System.out.println(pq.peek()); while (!pq.isEmpty()) { System.out.println(pq.remove()); System.out.println(pq); } } public static void testPriorityQueueWithStrings() { PriorityQueue pq = new BinaryHeap(); pq.add("Kona"); pq.add("Daisy"); pq.add("Meghan"); pq.add("Martin"); while (!pq.isEmpty()) { System.out.println(pq.remove()); } System.out.println(); } public static void testPriorityQueueWithPrintJobs() { PriorityQueue pjs = new BinaryHeap(); pjs.add(new PrintJob(1, "Kona", 3)); pjs.add(new PrintJob(2, "Daisy", 1)); pjs.add(new PrintJob(3, "Meghan", 3)); pjs.add(new PrintJob(4, "Kona", 2)); pjs.add(new PrintJob(5, "Martin", 1)); System.out.println(pjs); System.out.println(pjs.peek()); System.out.println(); while (!pjs.isEmpty()) { System.out.println(pjs.remove()); } } }