public void trickleDown(int index) { int largerChild; Node top = heapArray[index]; // save root while (index < currentSize / 2) // while node has at { // least one child, int leftChild = 2 * index + 1; int rightChild = leftChild + 1; if (rightChild < currentSize && heapArray[leftChild].getKey().nüfus < heapArray[rightChild].getKey().nüfus) { largerChild = rightChild; } else { largerChild = leftChild; } if (top.getKey().nüfus >= heapArray[largerChild].getKey().nüfus) { break; } heapArray[index] = heapArray[largerChild]; index = largerChild; } // end while heapArray[index] = top; // root to index }
//// ------------------------------------------------------------- public void trickleUp(int index) { int parent = (index - 1) / 2; Node bottom = heapArray[index]; while (index > 0 && heapArray[parent].getKey().nüfus < bottom.getKey().nüfus) { heapArray[index] = heapArray[parent]; // move it down index = parent; parent = (parent - 1) / 2; } // end while heapArray[index] = bottom; } // end trickleUp()