priority_queue<int ,vector<int > ,greater<int> >que;、
让队列中的元素从大到小排列--小的在顶部
#include<cstdio>
#include<stack>//头文件
#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()
{
int a=12;
stack<int > sta;
sta.push(a);//a进栈
sta.top();//栈的最后一个元素
sta.pop();//栈中最后一个出栈
sta.empty(); //判断栈中是否有元素
sta.size();//栈中元素个数
queue<int > qe;
qe.push(a);
qe.front();//最前的--
qe.pop();
qe.empty();
priority_queue<int > qu;//升序--
struct node now,qian;
qu.push(1 );
qu.push(3);
qu.push(2);
for (int i=0;i<3;i++)
{
int aa=qu.top();//最优先的
printf("%d\n",aa);
qu.pop();
}
priority_queue<node> que;//升序--
que.push(now );
que.push(qian);
for (int i=0;i<3;i++)
{
now=que.top();
printf("%d\n",now.value);
que.pop();
}
return 0;
}