主题:数据结构错误
#include<stdio.h>
typedef char ElemType;
#define MaxSize 100
typedef struct{
ElemType queue[MaxSize];
int front,rear;
}queuetype;
void initqueue(queuetype *Q)
{
Q->front=Q->rear=-1;
}
void enter(queuetype *Q,ElemType x)
{
if (Q->rear==MaxSize) printf("error");
else
{
Q->rear++;
Q->queue[Q->rear]=x;
}
}
void delete1(queuetype *Q)
{
if (Q->rear=Q->front=-1)printf("队列为空");
else
Q->front++;
}
ElemType gethead(queuetype *Q)
{
if (Q->rear=Q->front=-1)printf("队列为空") ;
else
{
return(Q->queue[Q->front+1]);
}
}
int empty(queuetype *Q)
{
if (Q->rear=Q->front=-1)return 1;
else return 0;
}
void display(queuetype *Q)
{int i;
if(Q->rear=Q->front=-1)printf("对列为空");
else
{
for (i=Q->front+1;i<=Q->rear;i++)
printf("%c\n",Q->queue[i]);
}
}
void main()
{
queuetype *qu;
printf("初始化队列\n");
initqueue(qu);
printf("队列空:%d",empty(qu));
printf("依次入队a,b,c,d:\n");
enter(qu,'a');
enter(qu,'b');
enter(qu,'c');
enter(qu,'d');
display(qu);
printf("出队一次:\n");
delete1(qu);
printf("队首元素:",gethead(qu));
}
//程序运行的时候为什么会出现内存错误????????请高手指教
typedef char ElemType;
#define MaxSize 100
typedef struct{
ElemType queue[MaxSize];
int front,rear;
}queuetype;
void initqueue(queuetype *Q)
{
Q->front=Q->rear=-1;
}
void enter(queuetype *Q,ElemType x)
{
if (Q->rear==MaxSize) printf("error");
else
{
Q->rear++;
Q->queue[Q->rear]=x;
}
}
void delete1(queuetype *Q)
{
if (Q->rear=Q->front=-1)printf("队列为空");
else
Q->front++;
}
ElemType gethead(queuetype *Q)
{
if (Q->rear=Q->front=-1)printf("队列为空") ;
else
{
return(Q->queue[Q->front+1]);
}
}
int empty(queuetype *Q)
{
if (Q->rear=Q->front=-1)return 1;
else return 0;
}
void display(queuetype *Q)
{int i;
if(Q->rear=Q->front=-1)printf("对列为空");
else
{
for (i=Q->front+1;i<=Q->rear;i++)
printf("%c\n",Q->queue[i]);
}
}
void main()
{
queuetype *qu;
printf("初始化队列\n");
initqueue(qu);
printf("队列空:%d",empty(qu));
printf("依次入队a,b,c,d:\n");
enter(qu,'a');
enter(qu,'b');
enter(qu,'c');
enter(qu,'d');
display(qu);
printf("出队一次:\n");
delete1(qu);
printf("队首元素:",gethead(qu));
}
//程序运行的时候为什么会出现内存错误????????请高手指教