C++ Check if the Priority Queue is Empty
wtfigi.wwidea.com
To check if a priority queue is empty in C++, you can use the empty()
method. It returns true
if the priority queue is empty, and false
otherwise. Here's an example:
#include <iostream> #include <queue> int main() { std::priority_queue<int> pq; if (pq.empty()) { std::cout << "The priority queue is empty." << std::endl; } else { std::cout << "The priority queue is not empty." << std::endl; } return 0; }
Output:
The priority queue is empty.