队列分为普通队列和循环队列
#include <iostream>
#include <queue>
using namespace std;
class Queue {
public:
explicit Queue(int n = 10) : arr(n), head(0), tail(0) {}
void push(int x) {
if (full()) {
cout << "Queue is full" << endl;
return;
}
arr[tail] = x;
tail++;
}
void pop() {
if (empty()) {
cout << "Queue is empty" << endl;
return;
}
head++;
}
bool full() {
return tail == arr.size();
}
bool empty() {
return head == tail;
}
int front() {
return arr[head];
}
int size() {
return tail - head;
}
void output() {
for (int i = head; i < tail; i++) {
cout << arr[i] << " ";
}
cout << endl;
}
private:
int head, tail;
vector<int> arr;
};
int main() {
string s;
int n;
Queue q(5);
while (true) {
cin >> s;
if (s == "push") {
cin >> n;
q.push(n);
cout << "size: " << q.size() << endl;
} else if (s == "pop") {
q.pop();
cout << "size: " << q.size() << endl;
} else if (s == "break") {
break;
}
q.output();
}
return 0;
}