Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

write a heap implementation of integer values, which highest priority element is

ID: 3537875 • Letter: W

Question

write a heap implementation of integer values, which highest priority

element is the one with the smallest key value. The implementation uses a minimum heap. You

need to modify the heap operations to keep the minimum, rather than maximum, element in the

root.


Sample input/output:

How many elements you have initially: 6

Enter the elements: 23 5 87 9 29 12

The heap is: 5 9 12 23 29 87

Press 1 for insert, press 2 for delete, or press 3 to exit program: 1

Enter the element: 29

The new heap is: 5 9 12 23 29 87 29

Press 1 for insert, press 2 for delete, or press 3 to exit program: 1

Enter the element: 7

The new heap is: 5 7 12 9 29 87 29 23

Press 1 for insert, press 2 for delete, or press 3 to exit program: 2

The deleted element is: 5

The new heap is: 7 9 12 23 29 87 29

Press 1 for insert, press 2 for delete, or press 3 to exit program: 2

The deleted element is: 7

The new heap is: 9 23 12 29 29 87

Press 1 for insert, press 2 for delete, or press 3 to exit program: 3

exit


Explanation / Answer

double Heap::deletemin() { double min = heap.front(); heap[0] = heap.at(heap.size()-1); heap.pop_back(); heapifydown(0); currentIndex--; return min; }