Comparable<Key>[] pq;
private int N = 0;
public boolean isEmpty() return N > 0;
public int size() return N;
public MaxPQ(int maxN) {
pq = (Key<key>[])new Comparable[maxN + 1];
}
public void add(Key key) {
pq[++N] = key;
swim(N);
}
public Key deletMax() {
Key max = pq[1];
exch(1, N--);
//what is missing here?
sink(1);
return max;
}
private void swim(int k) {
while(k > 1 && less(k/2, k)) {
exch(k/2, k);
k = k/2;
}
}
private void sink(int k) {
while(2*k <= N) {
int j = 2*k;
if(j < N && less (j, j + 1) j++;
if(!less(k, j)) break;
exch(k, j);
k = j;
}
}
}