题解 | #【模板】队列#

【模板】队列

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

相关推荐

点赞 评论 收藏
分享
犹豫的小狐狸刷了100道题:你是我在牛课上见到的最漂亮的女孩了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务