📜  优先级队列最小优先 - C++ 代码示例

📅  最后修改于: 2022-03-11 14:44:51.185000             🧑  作者: Mango

代码示例1
// C++ program to demonstrate min heap for priority queue
#include 
#include 
using namespace std;
 
void showpq(
    priority_queue, greater > gq)
{
    priority_queue, greater > g = gq;
    while (!g.empty()) {
        cout << '\t' << g.top();
        g.pop();
    }
    cout << '\n';
}
 
// Driver Code
int main()
{
    priority_queue, greater > gquiz;
    gquiz.push(10);
    gquiz.push(30);
    gquiz.push(20);
    gquiz.push(5);
    gquiz.push(1);
 
    cout << "The priority queue gquiz is : ";
    showpq(gquiz);
 
    cout << "\ngquiz.size() : " << gquiz.size();
    cout << "\ngquiz.top() : " << gquiz.top();
 
    cout << "\ngquiz.pop() : ";
    gquiz.pop();
    showpq(gquiz);
 
    return 0;
}