【队列】数组模拟队列_ios

【队列】数组模拟队列_c++_02

 

 

#include<iostream>
using namespace std;
const int N=100001;
int q[N],m,hh,tt=-1;
int main(){
    cin>>m;
    while(m--){
        string s;
        cin>>s;
        int x;
        if(s=="push"){
            cin>>x;
            q[++tt]=x;
        }
        else if(s=="pop"){
            hh++;
        }
        else if(s=="empty"){
            if(hh<=tt)cout<<"NO"<<endl;
            else cout<<"YES"<<endl;
        }
        else if(s=="query"){
            cout<<q[hh]<<endl;
        }
    }
    return 0;
}