Question: Lab#4 is on the heap implementation of priority queues. Do NOT use any of the STL in your code. Do NOT write a class. For
Lab#4 is on the heap implementation of priority queues.
Do NOT use any of the STL in your code. Do NOT write a class.
For the first part of this lab, you should write a C++ program that creates a priority queue implemented as a max-heap. For the second part, you should draw the resulting heap and upload the picture on Canvas.
1. Create a static integer array of 11 elements to hold the keys in the heap.
2. Insert 10 random positive integers (between 0 and 100) into the heap. The insert function should create a max-heap, where the biggest value has the highest priority. Pass the array, the new value, and the current size to the function.
3. Print the array in the main driver as shown in the execution example.
4. Write a deleteMax function (and any helper function as needed). The function should print all the children that shift up during the process and return the max value.
5. In the main function (i.e. the driver), ask the user for a positive integer X. Call the deleteMax function X times and print the max value for each call.
Execution example
[Labs]./lab4
heap = [ -, 95, 86, 62, 52, 51, 8, 39, 1, 36, 14]
How many values should we remove? 3
Moving child = 86 up
Moving child = 52 up
Moving child = 36 up 95 is deleted from the heap
Moving child = 62 up
Moving child = 39 up
86 is deleted from the heap
Moving child = 52 up
Moving child = 51 up
62 is deleted from the heap
End of Lab 4. Have a nice day!
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
