/** * Returns the minimum element of the heap and removes it. * * @throws IllegalStateException if the heap is empty. * * @return the minimum element in the heap before removing it. */ public int remove() { if (size == 0) throw new IllegalArgumentException("the heap is empty"); final int result = values[0]; removeUpdate(); return result; }