程序填空题:Deletes a given element at position p from a max-heap H
Please fill in the blanks in the program which deletes a given element at position p from a max-heap H.
```c++
Deletion ( PriorityQueue H, int p ) /* delete the element H->Elements[p] */
{
temp = H-> Elements[ H->Size-- ];
if ( temp > H->Elements[p] ) {
while ( (p != 1) && (@@[temp > H->Elements[p/2]](3)) ) {
H->Elements[p] = H->Elements[p/2];
p /= 2;
}
}
else {
while( (child = 2*p) <= H->Size) {
if ( child != H->Size && @@[H->Elements[child+1] >H->Elements[child]](3) )
child ++;
if ( @@[temp < H->Elements[child]](3)) {
H->Elements[p] = H->Elements[child];
p = child;
}
else
break;
}
}
H->Elements[p] = temp;
}
```
答案:
第1空:temp > H->Elements[p/2]
第2空:H->Elements[child+1] >H->Elements[child]
第3空:temp < H->Elements[child]
```c++
Deletion ( PriorityQueue H, int p ) /* delete the element H->Elements[p] */
{
temp = H-> Elements[ H->Size-- ];
if ( temp > H->Elements[p] ) {
while ( (p != 1) && (@@[temp > H->Elements[p/2]](3)) ) {
H->Elements[p] = H->Elements[p/2];
p /= 2;
}
}
else {
while( (child = 2*p) <= H->Size) {
if ( child != H->Size && @@[H->Elements[child+1] >H->Elements[child]](3) )
child ++;
if ( @@[temp < H->Elements[child]](3)) {
H->Elements[p] = H->Elements[child];
p = child;
}
else
break;
}
}
H->Elements[p] = temp;
}
```
答案:
第1空:temp > H->Elements[p/2]
第2空:H->Elements[child+1] >H->Elements[child]
第3空:temp < H->Elements[child]