#include <iostream>
#include <queue> // 优先级队列也在这里边,
#include <deque>
using namespace std;
int main()
{
//priority_queue<int, queue<int>> pq3;
priority_queue<int> pq; // 最大值优先级队列,默认的是vector类,
//priority_queue<int, deque<int>,greater<int>> pq2; //最小值优先级队列,
pq.push(-1);
pq.push(50);
pq.push(2);
pq.push(5);
cout << "优先级队列一共有:" << pq.size() << "个。" << endl;
while (!pq.empty())
{
cout << "从优先级队列中删除:" << pq.top() << endl;
pq.pop();
}
/*cout << endl << endl << "下面是最小值优先级队列:" << endl;
pq2.push(5);
pq2.push(9);
pq2.push(1);
pq2.push(100);
cout << pq2.top() << endl;
while (!pq2.empty())
{
cout << pq2.top() << endl;
pq2.pop();
}
if (pq2.empty())
cout << "没有数据了。" << endl;*/
return 0;
}
优先级队列priority_queue
最新推荐文章于 2024-06-22 09:02:14 发布