C++ 代码
#include <iostream>
using namespace std;
const int N = 100010;
int q[N], hh, tt = -1;
int main()
{
int m;
cin >> m;
while(m --)
{
string op;
int x;
cin>>op;
if(op == "push")
{
cin >> x;
q[++ tt] = x;
}
else if(op == "empty")
{
if(hh <= tt) printf("NO\n");
else printf("YES\n");
}
else if(op == "pop")
{
hh ++;
}
else
{
printf("%d\n", q[hh]);
}
}
return 0;
}