目 录CONTENT

文章目录

828. 模拟队列

不争
2024-01-02 / 0 评论 / 0 点赞 / 6 阅读 / 871 字

829. 模拟队列

image-20220121183835519

#include<iostream>

using namespace std;

const int N = 100010;

int q[N], hh, tt = -1;

void push(int x){
    q[ ++ tt] = x;
}
void pop(){
    hh++;
}
void empty(){
    if(hh <= tt)cout << "NO" << endl;
    else cout << "YES" << endl;
}
void query(){
    cout << q[hh] << endl;
}




int main(){
    int m ,x;
    string op;
    cin >> m;

    while(m --){
        cin >> op;
        if(op == "push"){
            cin >> x;
            push(x);
        }else if(op == "query"){
            query();
        }else if(op == "pop"){
            pop();
        }else{
            empty();
        }
    }




    return 0;
}
0

评论区