题解 | #【模板】队列#

【模板】队列

https://www.nowcoder.com/practice/afe812c80ad946f4b292a26dd13ba549

#include <stdio.h>
#include<malloc.h>
int main() {
int times ;
scanf("%d",×);
int queue[100000];
int head =0;
int tail = 0;
for(int i=0;i<times;i++){
    char* op = (char*)malloc(sizeof(char)*6);
    scanf("%s",op);
    if(!strcmp(op,"push")){
        int tmp;
        scanf("%d",&tmp);
        queue[tail++] = tmp;
    }
    if(!strcmp(op,"pop")){
        if(tail<=head){
            printf("error\n");
        }else{
  printf("%d\n",queue[head++]);
        }
      
    }
    if(!strcmp(op, "front")){
            if(tail<=head){
            printf("error\n");
        }
      else{
          printf("%d\n",queue[head]);
      }
    }
}
return 0;
}

全部评论

相关推荐

10-09 16:23
门头沟学院 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务