题目描述
数组模拟队列
C++代码
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int q[N], h = 0, t = 0;
bool empty(){
return h == t;
}
void push(int x){
q[t++] = x;
}
int pop(){
return q[h++];
}
int query(){
return q[h];
}
int main(){
int m, x;
string op;
cin >> m;
while(m--){
cin >> op;
if(op == "push"){
cin >> x;
push(x);
}
else if(op == "pop"){
pop();
}
else if(op == "query"){
cout << query() << endl;
}
else{
if(empty())
cout << "YES" << endl;
else
cout << "NO" << endl;
}
}
}