code: @Override
      @SuppressWarnings("unchecked")
      public K deleteMax() {
          K result;
          switch (size) {
          case 0:
              throw new NoSuchElementException();
          case 1:
              result = array[1];
              array[1] = null;
              size--;
              break;
          case 2:
              result = array[2];
              array[2] = null;
              size--;
              break;
          default:
              if (comparator == null) {
                  if (((Comparable<? super K>) array[3]).compareTo(array[2]) > 0) {
                      result = array[3];
                      array[3] = array[size];
                      array[size] = null;
                      size--;
                      if (size >= 3) {
                          fixdownMax(3);
                      }
                  } else {
                      result = array[2];
                      array[2] = array[size];
                      array[size] = null;
                      size--;
                      fixdownMax(2);
                  }
              } else {
                  if (comparator.compare(array[3], array[2]) > 0) {
                      result = array[3];
                      array[3] = array[size];
                      array[size] = null;
                      size--;
                      if (size >= 3) {
                          fixdownMaxWithComparator(3);
                      }
                  } else {
                      result = array[2];
                      array[2] = array[size];
                      array[size] = null;
                      size--;
                      fixdownMaxWithComparator(2);
                  }
              }
              break;
          }
  
          if (Constants.NOT_BENCHMARK) {
              if (2 * minCapacity < array.length - 1 && 4 * size < array.length - 1) {
                  ensureCapacity((array.length - 1) / 2);
              }
          }
  
          return result;
      }
docs: {@inheritDoc}