#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_SIZE 100000 // 修改队列的最大容量
struct node {
int data[MAX_SIZE];
int front;
int rear;
};
typedef struct node* queue;
void push(queue ptrs, int item) {
if ((ptrs->rear + 1) % MAX_SIZE == ptrs->front) {
printf("error\n"); // 队列已满,无法入队
return;
}
ptrs->rear = (ptrs->rear + 1) % MAX_SIZE;
ptrs->data[ptrs->rear] = item;
}
int pop(queue ptrs) {
if (ptrs->front == ptrs->rear) {
printf("error\n"); // 队列为空,无法出队
return -1;
}
ptrs->front = (ptrs->front + 1) % MAX_SIZE;
return ptrs->data[ptrs->front];
}
void front(queue ptrs) {
if (ptrs->front == ptrs->rear) {
printf("error\n"); // 队列为空,无法获取头元素
return;
}
printf("%d\n", ptrs->data[(ptrs->front + 1) % MAX_SIZE]);
}
int main() {
queue ptrs = (queue)malloc(sizeof(struct node));
ptrs->front = 0;
ptrs->rear = 0;
int n;
scanf("%d", &n);
char operation[10];
int value;
while (n--) {
scanf("%s", operation);
if (strcmp(operation, "push") == 0) {
scanf("%d", &value);
push(ptrs, value);
} else if (strcmp(operation, "pop") == 0) {
int result = pop(ptrs);
if (result != -1) {
printf("%d\n", result);
}
} else if (strcmp(operation, "front") == 0) {
front(ptrs);
}
}
free(ptrs);
return 0;
}