Question: Write a C++ program called heap.cpp to conduct heap operations. When the program starts, it should read a set of numbers from a user. After
Write a C++ program called heap.cpp to conduct heap operations. When the program starts, it should read a set of numbers from a user. After that, your program should display if its a heap or not. If its not a heap, your program should construct a heap with the numbers. Then, your program should conduct heap operation(s). For the program, your heap should be implemented using a dynamic array.
IT NEEDS TO RUN EXACTLY LIKE BELOW, USING A DYNAMIC ARRAY:
Input size: 5
Enter numbers: 20 7 8 1 3
This is a heap.
Select an operation
1: Insert a number
2. Delete the max
3. Heapsort & Quit
1
Enter a number: 5
Updated heap: 20 7 8 1 3 5
Select an operation
1: Insert a number
2. Delete the max
3. Heapsort & Quit
2
Updated heap: 8 7 5 1 3
Select an operation
1: Insert a number
2. Delete the max
3. Heapsort & Quit
2
Updated heap: 7 3 5 1
Select an operation
1: Insert a number
2. Delete the max
3. Heapsort & Quit
3
Heapsort: 7 5 3 1
Bye!
This is another sample run:
Input size: 3
Enter numbers: 1 3 7
This is NOT a heap.
Heap constructed: 7 3 1
Select an operation
1: Insert a number
2. Delete the max
3. Heapsort & Quit
1
Enter a number: 100
Updated heap: 100 7 1 3
Select an operation
1: Insert a number
2. Delete the max
3. Heapsort & Quit
3
Heapsort: 100 7 3 1
Bye!
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
