队列模板
1、普通队列模板
int q[N], hh = 0, tt = -1;
q[ ++ tt] = x;
hh ++ ;
q[hh];
if (hh <= tt)
{
}
2、循环队列模板
int q[N], hh = 0, tt = 0;
q[tt ++ ] = x;
if (tt == N) tt = 0;
hh ++ ;
if (hh == N) hh = 0;
q[hh];
if (hh != tt)
{
}
模拟普通队列
AC代码
#include<iostream>
using namespace std;
const int N=100004;
int q[N];
int hh=0,tt=-1;
int main(){
int m,x;
string op;
cin>>m;
for(int i=0;i<m;i++){
cin>>op;
if(op=="push"){
cin>>x;
q[++tt]=x;
}else if(op=="pop"){
hh++;
}else if(op=="query"){
cout<<q[hh]<<endl;
}else{
if(hh<=tt){
cout<<"NO"<<endl;
}else{
cout<<"YES"<<endl;
}
}
}
return 0;
}