game-ai/src/main/java/com/jzy/game/ai/util/BinaryHeap.java
/**
     * Given an index in the heap array, percolate that key down the heap.
     *
     * @param index an index into the heap array
     */
Given an index in the heap array, percolate that key down the heap.
@param index an index into the heap array
Given an index in the heap array percolate that key down the heap . @param index an index into the heap array
public void percolateDown(int index) {
        int child;
        E temp = elements[index];
        while (2 * index <= size) {
            child = 2 * index;
            if ((child != size)
                    && (elements[child + 1].compareTo(elements[child]) < 0)) {
                child++;
            }
            if (elements[child].compareTo(temp) < 0) {
                elements[index] = elements[child];
                index = child;
            } else {
                break;
            }
        }
        elements[index] = temp;
    }
public void percolateDown ( int index ) { int child ; E temp = elements [ index ] ; while ( 2 * index <= size ) { child = 2 * index ; if ( ( child != size ) && ( elements [ child + 1 ] . compareTo ( elements [ child ] ) < 0 ) ) { child ++ ; } if ( elements [ child ] . compareTo ( temp ) < 0 ) { elements [ index ] = elements [ child ] ; index = child ; } else { break ; } } elements [ index ] = temp ; }
Given an index in the heap array, percolate that key down the heap.
Given an index in the heap array percolate that key down the heap .
// ASSERT: at this point, elements[child] is the smaller of // the two children