← Quiz: STL Containers: all 9 questions
Quiz: STL Containers · Question 7 of 9
What does this print? (code)
What does this print?
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
int main() {
priority_queue<int, vector<int>, greater<int>> pq;
for (int x : {40, 10, 30, 20}) pq.push(x);
pq.pop();
cout << pq.top() << " " << pq.size() << "\n";
return 0;
}
- A.40 3
- B.10 3
- C.20 3
- D.30 4
Answer & explanation
Correct answer: 20 3
With greater<int> it is a min-heap: pop removes 10, so the smallest left is 20 and three items remain.
Can you get the rest right without peeking?
Take the timed Quiz: STL Containers quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →