subject

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

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 12:30
Which of the choices sean are not true when considering virus behavior
Answers: 1
question
Computers and Technology, 24.06.2019 17:50
Acontact list is a place where you can store a specific contact with other associated information such as a phone number, email address, birthday, etc. write a program that first takes in word pairs that consist of a name and a phone number (both strings). that list is followed by a name, and your program should output that name's phone number.
Answers: 1
question
Computers and Technology, 25.06.2019 06:50
The federal sentencing guidelines for organizations set the tone for organizational ethics compliance programs by question 1 options: a) codifying into law incentives for organizations to take action such as developing ethical compliance programs to prevent misconduct. b) forcing all organizations to develop mandatory reporting systems and ethics programs. c) eliminating most of the federal legislation that created inefficient and time-consuming activities for businesses. d) providing detailed guidelines for how to set up organizational ethics programs to guard against unethical conduct. e) providing a thorough examination of company codes of ethics to determine whether they are sufficient.
Answers: 1
question
Computers and Technology, 25.06.2019 10:00
*jenny is preparing a presentation on the health statistics of the 10 most populated countries. she wants to apply a blinking effect to the names of the countries, and a motion effect between the exit and entry of every slide. which options should she use? jenny should use the option to apply a special blinking effect to the names of the countries and the option to apply a motion effect between the exit and entry of every slide.
Answers: 2
You know the right answer?
Design and implement a heap sort program to display the max heap, remove the highest node and add a...
Questions
question
Mathematics, 17.12.2021 01:00
question
Health, 17.12.2021 01:00
Questions on the website: 13722359