@SuppressWarnings({"unchecked"})
    private void heapifyMax(int index) {

        int left = getLeft(index);
        int right = getRight(index);
        int greatest;

        if (left < size && comparator.compare((T) queue[left], (T) queue[index]) > 0) {
            greatest = left;
        } else {
            greatest = index;
        }

        if (right < size && comparator.compare((T) queue[right], (T) queue[greatest]) > 0) {
            greatest = right;
        }

        if (greatest != index) {
            swap(index, greatest);
            heapifyMax(greatest);
        }
    }