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

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 02:30, amaliabarrera9
The can be used to paste text in any order
Answers: 1
image
Computers and Technology, 23.06.2019 00:30, alex7078
Quick pl which one of the following is considered a peripheral? a software b mouse c usb connector d motherboard
Answers: 1
image
Computers and Technology, 23.06.2019 05:00, bellad0124outlookcom
In cell b18, enter a formula to calculate the amount budgeted for meals. this amount is based on the daily meal allowance and the total travel days (# of nights+1).
Answers: 1
image
Computers and Technology, 23.06.2019 07:30, jackie0833
Which option allows you to view slides on the full computer screen?
Answers: 1
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 in other subjects:

Konu
Geography, 26.09.2019 04:50