数据结构:模拟队列
- 题目描述
- 参考代码
题目描述
输入样例
10
push 6
empty
query
pop
empty
push 3
push 4
pop
query
push 6
输出样例
NO
6
YES
4
参考代码
#include <iostream>using namespace std;const int N = 100010;int q[N], hh, tt;int m, x;
string op;void init()
{hh = 0;tt = -1;
}void push(int x)
{q[++tt] = x;
}void pop()
{hh++;
}string empty()
{return tt < hh ? "Yes" : "No";
}int query()
{return q[hh];
}int main()
{init();cin >> m;while (m--){cin >> op;if (op == "push"){cin >> x;push(x);}else if (op == "pop"){pop();}else if (op == "empty"){cout << empty() << endl;}else{cout << query() << endl;}}return 0;
}