Question
IN C++ A min-heap is a Heap in which each node is less than or equal to any of its children. Implement add and remove
IN C++
A min-heap is a Heap in which each node is less than or equal to any of its children. Implement addand remove methods for the min-heap (MinHeap) class. Min-heaps are often used to implement priority queues.
NOTE:
- You need to implement the add and remove methods in the MinHeap class.
- The Driver class will call your add and remove method to construct the heap.
//First input line is the test method case (1 to add elements to the heap, 2 to remove one element from the heap and 3 to remove all the elements)
//Second input line is the number of elements (1 or more)
//Third input line is the list of elements
Sample input1 (Test add method):
1
4
7 3 8 1
Sample output1
1 3 8 7
Sample input2 (Test remove method):
2
4
7 3 8 1
Sample output2
1
Sample input3 (Test min heap sort):
3
4
7 3 8 1
Sample output3
1 3 7 8
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started