解题思路:
注意事项:
参考代码:
#include <stdio.h>
#include <stdlib.h>
#define len sizeof(Queue)
typedef struct s{
int data[100];
int front,rear;
}Queue;
void enqueue(Queue *h,int n){
h->rear++;
h->data[h->rear]=n;
}
int dequeue(Queue *h){
if (h->rear==h->front){
printf ("no\n");
return 0;
}
h->front++;
printf ("%d\n",h->data[h->front]);
return 1;
}
void fqueue(Queue *h){
printf ("%d\n",h->rear-h->front);
}
int main (){
Queue *h;
h=(Queue *)malloc(len);
int n,t,a;
scanf ("%d",&n);
for (int i=0;i<n;i++){
scanf ("%d",&t);
if (t==1){
scanf ("%d",&a);
enqueue(h,a);
}else if (t==2){
if (dequeue(h)==0){
return 0;
}
}else if (t==3){
fqueue(h);
}
}
}
0.0分
0 人评分
C语言程序设计教程(第三版)课后习题7.2 (C语言代码)浏览:533 |
C语言程序设计教程(第三版)课后习题8.8 (C语言代码)浏览:581 |
简单的a+b (C语言代码)浏览:647 |
C语言程序设计教程(第三版)课后习题5.7 (C语言代码)浏览:596 |
母牛的故事 (C语言代码)浏览:716 |
C语言程序设计教程(第三版)课后习题3.7 (C语言代码)浏览:550 |
简单的a+b (C语言代码)浏览:419 |
C语言程序设计教程(第三版)课后习题5.7 (C语言代码)浏览:401 |
1197求助浏览:631 |
C语言程序设计教程(第三版)课后习题7.5 (C语言代码)浏览:555 |