题解 | #【模板】队列#

【模板】队列

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;
}
全部评论

相关推荐

qq乃乃好喝到咩噗茶:院校后面加上211标签,放大加粗,招呼语也写上211
点赞 评论 收藏
分享
06-26 17:24
已编辑
宁波大学 Java
一口洪烧肉:哈哈哈哈哈哈哈哈哈哈哈硬要啊
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务