Question: 2 The C function popMinHeap() given below is supposed to delete the smallest integer from a inin heap which is stored in an integer array

2 The C function popMinHeap() given below is supposed to delete the smallest integer from a inin 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 int pop MinHeap(int *n, int* heap) { int parent, child, min, tmp; 3 min = heap[1]; tmp = heap[n--]; 4 parent = 1; child = 2; 5 while (child heap(child + 1])) 7 child++; 8 if (tmp > heap[child]) break; 9 heap[parent] = heap (child); parent = child; 10 child = parent*2; } 11 heap[parent] = tmp: 12 return min; 13]
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
