Min Heap implementation
Submissions: 2459   Accuracy:

70.09%

  Difficulty: Easy   Marks: 2
Associated Course(s):   Fork CPP

Given a priority queue (max heap) and Q queries to be performed on priority queue. The task is to perform operations based on queries.
1. p : query to push element (x, given with query) to priority_queue and print size.
2. pp : query to pop element from priority_queue and print size.
3. t : query to return top element of priority_queue, if empty -1 will be printed.

Input Format:
First line of input contains number of testcases T. For each testcase, first line of input contains Q queries. Next Q lines contains Q queries.

Output Format:
For each testcase, perform the required operation, and print if anything required.

Your Task:
Your task is to complete the functions push_pq(), pp_pq() and pq_top(), so that the queries are performed.

Constraints:
1 <= T <= 100
1 <= Q <= 100

Example:
Input:

1
5
p 5
p 3
p 1
t
pp

Output:
1
2
3
1
2

Explanation:
Testcase 1:
Pushing 5, 3, 1 to queue. Now, fetching top which is 1 (according to min heap property smallest element at top). Popping back element from queue, size reduced to 2.

** For More Input/Output Examples Use 'Expected Output' option **

Author: Dhiman Mayank


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.


to report an issue on this page.