#include<queue>
#include<iostream>
using namespace std;
struct mytype
{
int x;
};
struct comp
{
bool operator()(mytype a, mytype b)
{
return a.x > b.x;
}
};
bool operator < (mytype a, mytype b)
{
return a.x < b.x;
}
int main()
{
//基本数据类型
priority_queue<int> pq; //使用默认模板参数(最大堆)
priority_queue<int,vector<int>,greater<int> > pq1; //最小堆
//自定义数据类型
priority_queue<mytype,vector<mytype>,comp> pq2; //指定三个参数
priority_queue<mytype> pq3;//重载operator<后,声明对象时就可以只带一个模板参数
}
priority_queue指定模板参数
最新推荐文章于 2025-05-10 20:02:54 发布