题解 | 【模板】队列
【模板】队列
https://www.nowcoder.com/practice/afe812c80ad946f4b292a26dd13ba549
#include <stdio.h>
int main() {
int n;
scanf("%d",&n);
char s[6];
int x;
int queue[100000];
int top = 0;
int rear = 0;
for (int i = 0; i < n; i++) {
scanf("%s", s);
//printf("%c",s[5]);
if (s[0] == 'p' && s[1] == 'u') {
scanf("%d",&x);
queue[rear] = x;
rear++;
}
if (s[0] == 'p' && s[1] == 'o') {
if (top == rear) {
printf("error\n");
}
else {
printf("%d\n", queue[top]);
top++;
}
}
if(s[0]=='f'){
if (top == rear) {
printf("error\n");
} else {
printf("%d\n", queue[top]);
}
}
}
return 0;
}


阿里云成长空间 743人发布