Question 8
Back to Exercise
The program below does not compile. Which statement correctly describes the problem?
#include <iostream>
#include <queue>
int main() {
std::priority_queue<int> pq;
pq.push(4);
pq.push(9);
std::cout << pq.front() << '\n';
return 0;
}
- A push needs two arguments
- B priority_queue has top(), not front(); front()/back() belong to std::queue Correct
- C priority_queue must be a min-heap
- D int is not comparable
Correct Answer: Option B
pq.top() returns 9, the largest element.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!