in many ways For example, a linked list could be used The item would be inserted in descending order The largest item would be at the beginning of the list
used The item would be inserted into the binary tree The largest item would be at the rightmost node • Typically, a heap is used to implement a priority queue
This is an array-based heap • Data fields • MAX_ARRAY_SIZE, indexOfLastElement, array • Public methods • Heap, toString, empty, add, get, remove, and main
the constructor, which initializes the data fields public Heap() { } • Data fields: private final int MAX_ARRAY_SIZE = 100; private int indexOfLastElement = -1; private T array[] = (T[]) new Object[MAX_ARRAY_SIZE];
cast to java.lang.Comparable each element being compared is individually cast to java.lang.Comparable The compare() method casts the parameter to java.lang.Comparable, and then calls the compareTo() method for that particular variable’s class
priority queue contains a heap & calls the heap’s methods Same method names for Queue class, but a PriorityQueue (first-in highest-out) works slightly different than a Queue (first-in last-out)
1.Do the assignment corresponding to this lecture 2.Email me any questions you may have about the material 3.Turn in the assignment before the due date 4.Eat some grits!