队列
数组模拟队列
题目链接:AcWing 829. 模拟队列
#include <iostream>
using namespace std;
const int N = 100010;
int n;
int q[N];
int hh = 0, tt = -1;
void push(int x) { q[++ tt] = x; }
void pop() { hh ++; }
bool empty() { return hh > tt; }
int query() { return q[hh]; }
int main()
{
cin >> n;
while (n -- ) {
string op;
cin >> op;
if (op == "push") {
int x;
cin >> x;
push(x);
}
else if (op == "pop") pop();
else if (op == "empty") {
if (empty()) puts("YES");
else puts("NO");
}
else {
cout << query() << endl;
}
}
return 0;
}