Question: The C function popMinHeap() given below is supposed to delete the smallest integer from a min heap which is stored in an integer array
The C function popMinHeap() given below is supposed to delete the smallest integer from a min heap which is stored in an integer array heap[]. After executing popMinHeap(), the heap remains as a min heap structure. Variable n indicates the number of keys contained in array heap[]. Unfortunately, popMinHeap() has some bugs. Please correct all the bugs in the program. DO NOT rewrite the entire program, just show your modification with the line number. (10 points) 1 2 3 4 5 TT84HM23 6 7 9 10 11 12 13 int popMinHeap(int *n, int* heap) { int parent, child, min, tmp; min = heap[1]; } tmp = heap[n--]; child = 2; parent = 1; while (child heap[child]) break; heap[parent] = heap [child]; child parent*2; } heap[parent] = tmp; return min; parent = child;
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
