#include <iostream>
#include <string>
using namespace std ;
class Queue {
private :
int q[100010] ;
int head = 0, tail = 0 ;
public :
void push(int x) { // 加入队尾
q[tail ++] = x ;
}
void front() { // 查看队头
if (head == tail) cout << "error" << endl ;
else cout << q[head] << endl ;
}
void pop() { // 弹出队头
if (head == tail) cout << "error" << endl ;
else cout << q[head ++] << endl ;
}
};
int main() {
int n ;
cin >> n ;
Queue q ;
for (int i = 0 ; i < n ; i ++ ) {
string op ;
cin >> op ;
if (op == "push") {
int x ;
cin >> x ;
q.push(x) ;
}
else if (op == "pop") {
q.pop() ;
}
else if (op == "front") {
q.front() ;
}
}
return 0 ;
}
C++数据结构:队列模板
于 2024-02-23 12:02:17 首次发布