数据结构
```c
#include
#include
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
#define MAX_NUM 6
typedef struct{
int queue[MAX_NUM];
int front;
int rear;
int s;
}Queue_Type;
Queue_Type *p;
void InitQueue(Queue_Type *p)
{
p->front = 0;
p->rear = 0;
p->s =0;
}
void OutQueue(Queue_Type *p,int m)
{
int i,y;
for(i=1;i<6;i++)
{
printf("%d",p->front);
p->front = p->front % m + 1;
y=p->queue[p->front - 1];
if(p->front == p->rear)
p->s==0;
}
}
void InQueue(Queue_Type *p,int m)
{
int x;
if((p->s==1)&&(p->rear == p->front))
printf("overflow!\n");
else{
scanf("%d",p->queue[p->rear]);
p->rear +=1;
if(p->rear == m+1)
p->rear = 1;
p->queue[p->rear - 1]=x;
p->s=1;
}
OutQueue(p,6);
}
int main() {
printf("请输入五组数据:\n");
InitQueue(p);
InQueue(p,6);
return 0;
}
###### 运行结果及报错内容
不能输入,直接运行结束
Queue_Type *p 指针没有分配空间啊
建议改成 Queue_Type p;然后InitQueue(&p);这样子,后续参数为Queue_Type 类型的,都传递&p就好了
或者在main函数开始时加上
p = (Queue_Type)malloc(sizeof(Queue_Type));