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
은 무엇을합니까? (나는 숙제를하기 위해 알아야하는데, 힙에 특정 키를 제거하는 함수를 작성해야만한다.)간단한 힙 프로그램 -이 변수는 무엇을합니까
함수에서 한 번만 사용되었습니다. 사용 된 곳이 'if'인지 알아 내려고합니다 ... –