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 20:50
What is the difference between windows 7 and windows 10?
Answers: 1
question
Computers and Technology, 23.06.2019 09:00
Which best describes the role or restriction enzymes in the analysis of edna a. to break dna into fragments that vary in size so they can be sorted and analyzed b. to amplify small amounts of dna and generate large amounts of dna for analysis c. to purify samples of dna obtained from the environment so they can be analyzed d. to sort different sizes of dna fragments into a banding pattern that can be analyzed
Answers: 1
question
Computers and Technology, 23.06.2019 19:30
Anul 2017 tocmai s-a încheiat, suntem trişti deoarece era număr prim, însă avem şi o veste bună, anul 2018 este produs de două numere prime, 2 şi 1009. dorel, un adevărat colecţionar de numere prime, şi-a pus întrebarea: “câte numere dintr-un interval [a,b] se pot scrie ca produs de două numere prime? “.
Answers: 1
question
Computers and Technology, 23.06.2019 21:40
Simon says is a memory game where "simon" outputs a sequence of 10 characters (r, g, b, y) and the user must repeat the sequence. create a for loop that compares the two strings. for each match, add one point to user_score. upon a mismatch, end the game. sample output with inputs: 'rrgbryybgy' 'rrgbbrybgy'
Answers: 3
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, 24.02.2020 18:55
question
Mathematics, 24.02.2020 18:56
Questions on the website: 13722367