code: private static <T> void siftDownComparable(int k, T x, Object[] array,
                                                 int n) {
          if (n > 0) {
              Comparable<? super T> key = (Comparable<? super T>)x;
              int half = n >>> 1;           // loop while a non-leaf
              while (k < half) {
                  int child = (k << 1) + 1; // assume left child is least
                  Object c = array[child];
                  int right = child + 1;
                  if (right < n &&
                      ((Comparable<? super T>) c).compareTo((T) array[right]) > 0)
                      c = array[child = right];
                  if (key.compareTo((T) c) <= 0)
                      break;
                  array[k] = c;
                  k = child;
              }
              array[k] = key;
          }
      }
docs: Inserts item x at position k, maintaining heap invariant by
  demoting x down the tree repeatedly until it is less than or
  equal to its children or is a leaf.
  
  @param k the position to fill
  @param x the item to insert
  @param array the heap array
  @param n heap size