AcWing 829. 模拟队列
原题链接
简单
作者:
风起于浮萍之末
,
2024-01-28 14:35:25
,
所有人可见
,
阅读 33
#include <iostream>
#include<cstring>
using namespace std;
const int N = 100010;
int q[N];
int hh = 0;//队头位置
int tt = -1;//队尾位置
int m;
string s;
void push(int x){// 入队 先移动 后加入元素怒
q[++tt] = x;
}
void pop(){// 弹出对头
hh++;
}
void empty(){// 队尾元素大于等于对头不空
if(tt >= hh) cout << "NO" << endl;
else cout << "YES" << endl;
}
void query (){// hh 是对头
cout << q[hh] << endl;
}
int main(){
cin >> m;
while(m--){
cin >> s;
//入队
if(s == "push"){
int x;
cin >> x;
push(x);
}
//出队
if(s == "pop"){
pop();
}
//问空
if(s == "empty"){
empty();
}
//问队头
if(s == "query"){
query();
}
}
}