队列元素打印不出来是哪错了,求帮助
#include <stdio.h>#include <malloc.h>
#include <stdlib.h>
typedef char ElemType;
typedef struct QNode
{
ElemType data;
struct QNode *next;
}QNode,*QueuePrt;
typedef struct
{
QueuePrt front,rear;
}LinkQueue;
void InitQueue(LinkQueue *q)
{
q->front=(QueuePrt)malloc(sizeof(QNode));
if(!q->front)
exit(0);
q->front->next=NULL;
}
void InsertQueue(LinkQueue *q,ElemType e)
{
QueuePrt p;
p=(QueuePrt)malloc(sizeof(QNode));
if(!p)
exit(0);
p->data=e;
p->next=NULL;
q->rear->next=p;
q->rear=p;
}
void DeleteQueue(LinkQueue *q,ElemType *e)
{
QueuePrt p;
if(q->front==q->rear)
return;
p=q->front->next;
*e=p->data;
q->front->next=p->next;
if(q->rear==p)
q->rear=q->front;
free(p);
}
int main()
{
ElemType c;
LinkQueue q;
InitQueue(&q);
printf("请输入字符串\n");
scanf("%c",&c);
while(c != '#')
{
InsertQueue( &q, c);
scanf("%c",&c);
}
while(q.front != q.rear)
{
DeleteQueue(&q,&c);
printf("%c",c);
}
return 0;
} 初始化队列函数中没有交代s->rear的位置
页:
[1]