STL header files: #include <queue>
Priority queue:
Default from large to small arrange:priority_queuee<node>q;
Three ways to customize the priority:
1. Overloaded operators:
BOOL operator < (const node &a, const node &b) { return a.value < B.value;//Sort by value from large to small} priori ty_queue<node>q;
(const node &a is passed by reference, which is more efficient than passing node A by value, the effect is the same)
2. Custom comparison function template structure:
struct cmp{ bool operator () (const node &a, const node &b) { return a.value>b.value;// Sort by value from small to large }};p Riority_queue<node, Vector<node>, cmp>q;
3. Define friend action class overloaded functions
struct node{ int value; friend bool operator< (const node &a,const node &b) { return a.value<b.value; Arrange by value from large to small }};p riority_queue<node>q;
Comparison function for priority queue Priority_queue