C ++ priority queue priority_queue

Usually when defined directly on to get away:

priority_queue<int>Q;

The default large root heap.

Before time is very small root vegetables do not know how to write heap, add a minus sign done flung a large root heap of stupid to go inside the examination room still.

Its full form of it, in fact, is long like this:

 

//小根堆
priority_queue <int,vector<int>,greater<int> > Q;
//大根堆
priority_queue <int,vector<int>,less<int> >Q;

 

 

Then there are some special circumstances:

With the pair when the press first, then second automatic sorting.

priority_queue<pair<int,int> >Q;

 

If you want a custom sort, you can write a $ cmp $:

struct node{
    int a,b;
}num[N];
struct cmp
{
    bool operator()(const int &p,const int &q)
    {
        if(num[p].b<num[q].b) return 1;
        else return 0;
    }
};
priority_queue<int,vector<int>,cmp> Q;

 

To be continue...

 

Guess you like

Origin www.cnblogs.com/lyttt/p/11774367.html