#include <iostream>
#include <string>
using namespace std;
class queue {
public:
int l = 0;
int r = 0;
int q[1000000];
void pop() {
if (l == r) {
cout << "error" << endl;
} else {
cout << to_string(q[l]) << endl;
l++;
}
}
void front() {
if (l == r) {
cout << "error" << endl;
} else {
cout << to_string(q[l]) << endl;
}
}
void push (int num) {
q[r] = num;
r++;
}
};
int main() {
queue q;
int n;//操作个数
cin >> n;
for (int i = 0; i < n; i++) {
string op;
cin >> op;
if (op == "push") {
int num;
cin >> num;
q.push(num);
} else if (op == "front") {
q.front();
} else if (op == "pop") {
q.pop();
}
}
return 0;
}
// 64 位输出请用 printf("%lld")
题解 |队列|#【模板】队列#
最新推荐文章于 2024-11-18 18:38:00 发布