I am trying to learn java and I am stumped by this example- I can't find what the key is
public class OrderedArrayMaxPQ<Key extends Comparable<Key>> {
private Key[] pq; // elements
This is the example of the priority queue .. i got it from http://algs4.cs.princeton.edu/24pq/OrderedArrayMaxPQ.java.html I thought a priority queue should have a data + a priority value. I am not sure how these guys are doing it.
public class OrderedArrayMaxPQ<Key extends Comparable<Key>> {
private Key[] pq; // elements
private int N; // number of elements
// set inititial size of heap to hold size elements
public OrderedArrayMaxPQ(int capacity) {
pq = (Key[]) (new Comparable[capacity]);
N = 0;
}
public boolean isEmpty() { return N == 0; }
public int size() { return N; }
public Key delMax() { return pq[--N]; }
public void insert(Key key) {
int i = N-1;
while (i >= 0 && less(key, pq[i])) {
pq[i+1] = pq[i];
i--;
}
pq[i+1] = key;
N++;
}
@SuppressWarningsannotation for. Also (and probably more importantly), thedelMax()method fails to null out the no-longer-used reference, which may prevent keys that have been removed from the queue from being garbage collected.