#include<iostream>
#include<queue>
using namespace std;
struct cmp
{
bool operator()(int &a,int &b) const
{
return a<b;
}
};
int main()
{
cout<<"***************************************"<<endl;
cout<<"实现降序排列的优先队列!"<<endl;
cout<<"***************************************"<<endl;
priority_queue<int,vector<int>,cmp> q;
for(int i=1;i<=10;i++)
{
q.push(i);
cout<<"元素"<<i<<"已成功加入队列!"<<endl;
}
cout<<"将元素18与-1加入队列!"<<endl;
cout<<"***************************************"<<endl;
q.push(18);
q.push(-1);
int pos=1;
cout<<"***************************************"<<endl;
while(!q.empty())
{
cout<<"队列的第"<<pos++<<"个元素是:"<<q.top()<<endl;
q.pop();
}
cout<<"***************************************"<<endl;
cout<<"所有操作全部结束!"<<endl;
cout<<"***************************************"<<endl;
return 0;
}
C++ STL Priority Queue的基本操作
最新推荐文章于 2024-11-14 21:21:03 发布