Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(You can use the following code to generate random numbers in Step 2. #include srand(time(0)) rand()) Lab#4 is on the heap implementation of priority queues.

(You can use the following code to generate random numbers in Step 2.

#include

srand(time(0))

rand())

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.

image text in transcribed

Execution example [Labs]./lab4 heap = 1, 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! [Labs]./lab4 heap = 1, 100, 95, 84, 72, 60, 22, 4, 8, 21, 14] How many values should we remove? 4 Moving child = 95 up Moving child = 72 up Moving child = 21 up 100 is deleted from the heap Moving child = 84 up Moving child = 22 up 95 is deleted from the heap Moving child - 72 up Moving child = 60 up 84 is deleted from the heap Moving child = 60 up Moving child = 21 up 72 is deleted from the heap End of Lab 4. Have a nice day! Execution example [Labs]./lab4 heap = 1, 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! [Labs]./lab4 heap = 1, 100, 95, 84, 72, 60, 22, 4, 8, 21, 14] How many values should we remove? 4 Moving child = 95 up Moving child = 72 up Moving child = 21 up 100 is deleted from the heap Moving child = 84 up Moving child = 22 up 95 is deleted from the heap Moving child - 72 up Moving child = 60 up 84 is deleted from the heap Moving child = 60 up Moving child = 21 up 72 is deleted from the heap End of Lab 4. Have a nice day

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

3. How has Starbucks changed since its early days?

Answered: 1 week ago