题解 | #【模板】队列#

【模板】队列

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

相关推荐

notbeentak...:真的nc,算毕业6月份,要给这种b公司打半年多白工😅
点赞 评论 收藏
分享
09-13 08:41
服装/纺织设计
那一天的Java_J...:你第一次参加面试吗
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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