Question: 1) Heap Operation This question is designed to help you get a better understanding of basic heap operations. You will be given queries of types:
1) Heap Operation
This question is designed to help you get a better understanding of basic heap operations. You will be given queries of types:
"1 v " - Add an element to the heap.
"2 v " - Delete the element from the heap.
"3" - Print the minimum of all the elements in the heap.
NOTE: It is guaranteed that the element to be deleted will be there in the heap. Also, at any instant, only distinct elements will be in the heap.
Input Format
The first line contains the number of queries, Q . Each of the next Q lines contains a single query of any one of the above mentioned types.
Output Format
For each query of type 3, print the minimum value on a single line.
Explanation
After the first 2 queries, the heap contains {4,9}. Printing the minimum gives 4 as the output. Then, the 4th query deletes 4 from the heap, and the 5th query gives 9 as the output.
a. Implement it with Linked List (heap_linkedlist.cpp) b. Implement it with binary heap tree (heap_binary_tree.cpp)
__________________________________________
#include #include #include #include #include using namespace std;
int main() { /* Enter your code here. Read input from STDIN. Print output to STDOUT */ return 0; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
