示例#1
0
  private static void heapify(int[] a) {

    int startIndex = Heap.findParent(a.length - 1);

    while (startIndex >= 0) {
      siftDown(a, startIndex--, a.length);
    }
  }
示例#2
0
 private static void siftDown(int[] a, int k, int size) {
   int maxIndex;
   while (k >= 0 || k <= size - 1) {
     maxIndex = Heap.findSwapNode(a, k, size, Heap.IS_MAX_HEAP);
     if (maxIndex == k) return;
     Helper.swap(a, k, maxIndex);
     k = maxIndex;
   }
 }