结构体内嵌比较函数:
第一种情况简单的sort排序:
struct node
{
int a;
int b;
bool operator < (const node &t)const
{
return a > t.a;
}
};
这里内嵌的比较函数是按照a的值递减,但如果需要优先队列,且需要递减排列,那就需要写成这样:
struct node
{
int a;
int b;
bool operator < (const node &t)const
{
return a < t.a;
}
};
priority_queue <node> pque;
不难发现结构里内嵌的排序,sort排序与优先队列里的排序是相反的,这点要切记!