priority_queue优先队列容器
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
struct Info
{
string name;
float score;
bool operator < (const Info &a) const
{
return a.score<score;
}
};
struct myComp
{
bool operator() (const int &a, const int &b)
{
return a>b;
}
};
int main()
{
priority_queue<int> pq;
pq.push(1);
pq.push(2);
pq.push(3);
pq.push(9);
cout << pq.size() << endl;
while(pq.empty()!=true)
{
cout << pq.top() << ' ';
pq.pop();
}
cout << endl;
priority_queue<Info> pqs;
Info info;
info.name="Jim";
info.score=77.5;
pqs.push(info);
info.name="John";
info.score=95;
pqs.push(info);
info.name="Alen";
info.score=69;
pqs.push(info);
while(pqs.empty()!=true)
{
cout << pqs.top().name << ':' << pqs.top().score << endl;
pqs.pop();
}
priority_queue<int,vector<int>,myComp> pqv;
pqv.push(1);
pqv.push(9);
pqv.push(2);
pqv.push(30);
while(pqv.empty()!=true)
{
cout << pqv.top() << ' ';
pqv.pop();
}
cout << endl;
return 0;
}