void ReheapDown( int* heap, int top, int swpIndx, int numElements ) {
int leftChild = 2 * top + 1;
int rightChild = 2 * top + 2;
int minChild;
if (leftChild < numElements) {
// find subscript of smallest child
if (rightChild >= swpIndx || heap[leftChild] < heap[rightChild])
minChild = leftChild;
else
minChild = rightChild;
// if data at top is greater than smallest
// child then swap and continue
if (heap[top] > heap[minChild]) {
swap( heap[top], heap[minChild] );
ReheapDown( heap, minChild, swpIndx, numElements );
}
}
これは単純なヒープ用です。ReheapDownは、ヒープ内のアイテムを削除するために部分的に使用されます。しかし、何をしswpIndx
ますか?(私は宿題をすることを知る必要があります。そこでは、ヒープ内の特定のキーを削除する関数を作成することになっています。)