大哥们看我的程序哪里出错了

来源:百度知道 编辑:UC知道 时间:2024/06/30 05:16:59
#include<stdio.h>
#define MAXSIZE 10
typedef struct
{int data[MAXSIZE];
int front,rear;
}c_Sequeue;
c_Sequeue *q;
int Init_Sequeue(c_Sequeue *q,int x)
{if(q->rear-q->front>=MAXSIZE-1)
{print("dui man");
return -1;
}
else
{q->rear=(q->rear+1)%MAXSIZE;
q->data[q->rear]=x;
return 1;
}
}
main()
{int i,j;
i=1;
printf("Ru dui");
while(i==1)
{ scanf("%d",&j);
i=Init_Sequeue(c_Sequeue *q,j);
}
} 作业啊 大哥 谢谢了。。。

#include<stdio.h>
#define MAXSIZE 10
typedef struct
{
int data[MAXSIZE];
int front,rear;
}c_Sequeue;
c_Sequeue q; //这里

int Init_Sequeue(c_Sequeue *q,int x)
{
if(q->rear-q->front>=MAXSIZE-1)
{printf("dui man");
return -1;
}
else
{q->rear=(q->rear+1)%MAXSIZE;
q->data[q->rear]=x;
return 1;
}
}
void main() //这里
{
int i,j;
i=1;
printf("Ru dui");
while(i==1)
{ scanf("%d",&j);
i=Init_Sequeue(&q,j); //这里
}
}

你的Init_Sequeue(c_Sequeue *q,int x) 是用来入队 代码中 队列这个抽象数据类型 没有被初始化( q->rear = 0;q->front = 0; )

恩 楼上说的 偶都没注意到