package lab4; public class HeapTester { @SuppressWarnings("unchecked") public static void main(String args[]){ TaggedBinaryHeap h = new TaggedBinaryHeap(5); TaggedBinaryHeap.Tracker[] trackers = new TaggedBinaryHeap.Tracker[10]; System.out.println("The isEmpty method returns " + h.isEmpty() + "."); trackers[0] = h.putTracked(5.25,"a"); trackers[1] = h.putTracked(4.5,"b"); trackers[2] = h.putTracked(3.5,"c"); System.out.println("After inserting 5.25 (data a), 4.5 (data b), 3.5 (data c), the heap is:\n" + h); trackers[3] = h.putTracked(3.14,"d"); System.out.println("After inserting 3.14 (data d), the heap is:\n" + h); trackers[4] = h.putTracked(7.3,"e"); try { //checking that you throw a RuntimeException here h.putTracked(5.0,"x"); } catch (RuntimeException e) { System.out.println("Increasing the capacity from 5 to 10.\n"); h.ensureCapacity(10); } trackers[5] = h.putTracked(20.0,"f"); trackers[6] = h.putTracked(4.75,"g"); System.out.println("After inserting 7.3 (data e), 20 (data f), 4.75 (data g), the heap is:\n" + h); trackers[7] = h.putTracked(1.5,"h"); System.out.println("After inserting 1.5 (data h), the heap is:\n" + h); trackers[8] = h.putTracked(8.8,"i"); trackers[9] = h.putTracked(9.0,"j"); System.out.println("After inserting 8.8 (data i), 9.0 (data j), the heap is:\n" + h); System.out.println("There are " + h.getSize() + " elements in the heap."); System.out.println("The isEmpty method returns " + h.isEmpty() + ".\n"); System.out.println("removing d"); System.out.println(" get returns " + trackers[3].get()); trackers[3].remove(); System.out.println("The heap is:\n" + h); System.out.println("Updating tag for a from 5.25 to 1.0"); trackers[0].update(1.0); System.out.println("The heap is:\n" + h); System.out.println("Updating tag for c from 3.5 to 1.25"); trackers[2].update(1.25); System.out.println("The heap is:\n" + h); for (int i=0; i < 2; i++){ System.out.println("About to remove " + h.min()); h.extractMin(); for (int j = 0; j < 3; j++) System.out.println(" trackers[" + j + "].inCollection() returns " + trackers[j].inCollection()); System.out.println("The heap is:\n" + h); } System.out.println("Removing i"); System.out.println(" get returns " + trackers[8].get()); trackers[8].remove(); System.out.println("The heap is:\n" + h); System.out.println("Updating tag for h from 1.5 to 10.5"); trackers[7].update(10.5); System.out.println("The heap is:\n" + h); System.out.println("updating tag for b from 4.5 to 12.5"); trackers[1].update(12.5); System.out.println("The heap is:\n" + h); System.out.println("There are " + h.getSize() + " elements in the heap."); } }