栈和队列总结

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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值