模拟队列
int q[N];存元素
int hh = 0;//队头
int tt = -1;//队尾
代码如下:
#include<iostream>
using namespace std;
const int N = 100010;
int q[N],hh,m;
int tt = -1;
int main()
{
cin>>m;
while(m--)
{
string s;
int x;
cin>>s;
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
{
cout<<q[hh]<<endl;//输出队头元素
}
}
return 0;
}