Computers and Technology, 03.05.2020 13:12 jennychrin95
Design and implement a heap sort program to display the max heap, remove the highest node and add a new node. The program should have at least a header file and a main driver file.
Removing the root in a heap β after the root is removed, the tree must be rebuilt to maintain the heap property:
Move the last node to replace the root;
Let the root be the current node;
While ( the current node has children and the current node is smaller than one of its children)
{ Swap the current node with the larger of its children;
The current node now is one level down; }
Adding a new node β to add a new node to the heap, first add it to the end of the heap and then rebuild the tree as follows:
Let the last node be the current node;
While (the current node is greater than its parent)
{ Swap the current node with its parent;
The current node now is one level up;}
Sample output:
Enter the positive integers to put in heap, enter -9 to stop.
7 5 16 85 95 4 11 65 43 10 13 9 -9
The Heap is:
95 85 11 65 16 9 7 5 43 10 13 4
Display the Max-heap
Add an Item
Remove the Largest Item
Exit
Enter choice: 3
Remove Item: 95
Display the Max-heap
Add an Item
Remove the Largest Item
Exit
Enter choice: 3
Remove Item: 85
Display the Max-heap
Add an Item
Remove the Largest Item
Exit
Enter choice: 3
Remove Item: 65
Display the Max-heap
Add an Item
Remove the Largest Item
Exit
Enter choice: 1
The Heap is: 43 16 11 13 10 9 7 5 4
Display the Max-heap
Add an Item
Remove the Largest Item
Exit
Enter choice: 2
Add Item: 14
Display the Max-heap
Add an Item
Remove the Largest Item
Exit
Enter choice: 1
The Heap is: 43 16 11 13 14 9 7 5 4 10
Display the Max-heap
Add an Item
Remove the Largest Item
Exit
Answers: 2
Computers and Technology, 22.06.2019 06:00
Which of the following is a way that advancements in technology improve humans' ability to measure air quality and protect human health? a. air quality data gathered by new instruments can be used to reduce exposure to pollutants. b. new technologies enable natural and human-made pollution sources to be located and monitored. c. air quality data gathered by new instruments can be used to predict trends in pollution over time. d. new technologies allow governments to make informed decisions about the regulation of pollution. (choose more than one)
Answers: 2
Computers and Technology, 23.06.2019 03:50
Q-1 which of the following can exist as cloud-based it resources? a. physical serverb. virtual serverc. software programd. network device
Answers: 1
Computers and Technology, 23.06.2019 16:00
An english teacher would like to divide 8 boys and 10 girls into groups, each with the same combination of boys and girls and nobody left out. what is the greatest number of groups that can be formed?
Answers: 2
Computers and Technology, 24.06.2019 00:00
Afashion designer wants to increase awareness about her brand. which network can she use and why she can use the blank to blank her products online. answers for the first blank: internet, extranet, or intranet answers for the second blank: market, design, and export
Answers: 1
Design and implement a heap sort program to display the max heap, remove the highest node and add a...
History, 26.06.2019 00:00
Social Studies, 26.06.2019 00:00
Mathematics, 26.06.2019 00:00
Mathematics, 26.06.2019 00:00
English, 26.06.2019 00:00
Biology, 26.06.2019 00:00
Advanced Placement (AP), 26.06.2019 00:00
Mathematics, 26.06.2019 00:00
Mathematics, 26.06.2019 00:00