note: This article comes from the Internet. Please contact me via lethic@163.com if there is any infringement.
lethic@163.com.

priority_queue<int,vector<int>,greater<int>> ,

C++
#include<iostream>
#include<functional>
#include<queue>
using namespace std;

struct node
{
friend bool operator< (node n1, node n2)
{
return n1.priority < n2.priority;//”<“”>”
}
int priority;
int value;
};

int main()
{
const int len = 5;
int i;
int a[len] = {3,5,9,6,2};
//1
priority_queue<int> qi;//
for(i = 0; i < len; i++)
qi.push(a[i]);
for(i = 0; i < len; i++)
{
cout<<qi.top()<<” “;
qi.pop();
}
cout<<endl;

//2
priority_queue<int, vector<int>, greater<int> > qi2;//greaterless
for(i = 0; i < len; i++)
qi2.push(a[i]);
for(i = 0; i < len; i++)
{
cout<<qi2.top()<<” “;
qi2.pop();
}
cout<<endl;

//3
priority_queue<node> qn;//
node b[len];
b[0].priority = 6; b[0].value = 1;
b[1].priority = 9; b[1].value = 5;
b[2].priority = 2; b[2].value = 3;
b[3].priority = 8; b[3].value = 2;
b[4].priority = 1; b[4].value = 4;

for(i = 0; i < len; i++)
qn.push(b[i]);
cout<<“”<<‘\t'<<“”<<endl;
for(i = 0; i < len; i++)
{
cout<<qn.top().priority<<‘\t'<<qn.top().value<<endl;
qn.pop();
}
return 0;
}

1

int
main()
{
priority_queue<node> qn;

node n1;
n1.a = 9;
node n2;
n2.a = 2;
node n3;
n3.a = 50;

qn.push(n1);

qn.push(n2);

qn.push(n3);

int