数据结构用c语言实现循环队列的输入输出 请问我的代码出了什么问题?编译过了,但是一直循环
#include<stdio.h>#include<stdlib.h>#include<string.h>#include<math.h>#defineLsizeof(s...
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define L sizeof(struct queue)
#define Max 100
typedef struct queue
{
int data[Max];
int front;
int rear;
}queue;
struct queue *initial(queue *q)
{
q=(queue*)malloc(L);
q->front=0;
q->rear=q->front=0;
return q;
}
int input(queue *q)
{
int x;
if((q->rear+1)%Max==(q->front))
{
printf("ERROR!");
}
while(x!=0)
{
scanf("%d",&x);
q->data[q->rear]=x;
q->rear++;
}
return x;
}
int dele(queue *q)
{
int e;
if(q->front==q->rear)
{
printf("ERROR!");
}
while(q!=NULL)
{
e=q->data[q->front];
printf("%d",e);
q->front=(q->front+1)%(Max);
}
return e;
}
int main()
{
struct queue *initial(queue *);
int input(queue *);
int dele(queue *);
struct queue *q=NULL;
q=initial(q);
printf("There are the numbers:");
input(q);
printf("repeat:");
dele(q);
return 0;
} 展开
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define L sizeof(struct queue)
#define Max 100
typedef struct queue
{
int data[Max];
int front;
int rear;
}queue;
struct queue *initial(queue *q)
{
q=(queue*)malloc(L);
q->front=0;
q->rear=q->front=0;
return q;
}
int input(queue *q)
{
int x;
if((q->rear+1)%Max==(q->front))
{
printf("ERROR!");
}
while(x!=0)
{
scanf("%d",&x);
q->data[q->rear]=x;
q->rear++;
}
return x;
}
int dele(queue *q)
{
int e;
if(q->front==q->rear)
{
printf("ERROR!");
}
while(q!=NULL)
{
e=q->data[q->front];
printf("%d",e);
q->front=(q->front+1)%(Max);
}
return e;
}
int main()
{
struct queue *initial(queue *);
int input(queue *);
int dele(queue *);
struct queue *q=NULL;
q=initial(q);
printf("There are the numbers:");
input(q);
printf("repeat:");
dele(q);
return 0;
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询