题解 | #【模板】队列#

【模板】队列

http://www.nowcoder.com/practice/afe812c80ad946f4b292a26dd13ba549

#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int q[N];
int n, x;
int front = -1, back = -1;
string s;
int main()
{
    cin>>n;
    while (n--) {
        cin>>s;
        if (s == "push") {
            cin>>x;
            q[++back] = x;
        } else if (s == "pop") {
            if (front >= back) {
                cout<<"error"<<endl;
            } else {
                 cout<<q[++front]<<endl;
            }
        } else if (s == "front") {
            if (front >= back) {
                cout<<"error"<<endl;
            } else {
                cout<<q[front+1]<<endl;
            }
        }
    }

    return 0;
}
全部评论

相关推荐

不愿透露姓名的神秘牛友
02-12 18:14
RT,这周五就是情人节了,前女友给我发了消息,我该不该回?
Yoswell:原则上来说让她滚,但是本着工作很累下班想吃瓜的心态,我觉得你可以回一下
点赞 评论 收藏
分享
什么时候才能有offer啊_:十年前我还在刺激战场研究跳伞的底层原理呢
投递牛客等公司
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务