public T extractMax() {
            if (size == 0) throw new ArrayIndexOutOfBoundsException("the array is already empty");
            T head = heap.get(0);
            heap.set(0, heap.get(--size));
            siftDown(0);
            return head;
        }