Question discussion

What is the output of the following C++ program?#include #include #include #include using namespace std; int main() { priority_queue a; pri…

2313Medium DSSSB TGT Computer Science 0 replies 1 views
0

What is the output of the following C++ program?

#include <iostream>
#include <queue>
#include <vector>
#include <functional>
using namespace std;
int main() {
    priority_queue<int> a;
    priority_queue<int, vector<int>, greater<int>> b;
    for (int x : {5, 1, 8, 3}) { a.push(x); b.push(x); }
    a.pop(); b.pop();
    cout << a.top() << b.top();
    return 0;
}
  • A53
  • B83
  • C51
  • D13
Correct answer: A

Explanation

The default priority_queue is a max-heap, so a.pop() removes 8 and its top becomes 5; with greater it is a min-heap, so b.pop() removes 1 and its top becomes 3.

Discussion 0

Nobody has replied yet. Start the discussion!