- 1. 题目
- 2. 读题(需要重点注意的东西)
- 3. 解法
- 4. 可能有帮助的前置习题
- 5. 所用到的数据结构与算法思想
- 6. 总结
思路:用数组来实现一个队列q[N],用tt指向队尾,用hh指向队首
3. 解法---------------------------------------------------解法---------------------------------------------------
#include4. 可能有帮助的前置习题 5. 所用到的数据结构与算法思想 6. 总结using namespace std; const int N = 1e5+10; int q[N],hh,tt = -1; int main(){ int m; cin >> m; while(m--){ string op; cin >> op; if(op == "push"){ int x; cin >> x; q[++tt] = x; } if(op == "pop") hh++; if(op == "empty"){ if(hh <= tt) cout << "NO" << endl; else cout << "YES" << endl; } if(op == "query") cout << q[hh] << endl; } return 0; }
队列用数组实现的模板题,推荐完全背下来。


![[AcWing]829. 模拟队列(C++实现)栈模板题 [AcWing]829. 模拟队列(C++实现)栈模板题](http://www.mshxw.com/aiimages/31/456811.png)
