二叉树层次遍历,输入数据后没有输出结果

#include
#include
#define max 50
typedef struct bitnode
{
char data;
struct bitnode *lchild,*rchild;
}bitnode,*bitree;

typedef struct
{
bitnode *data[50];
int front,rear;
}queue;

void initqueue(queue *q)
{
q->front=q->rear;
}

int isempty(queue *q)
{
return q->rear==q->front?1:0;
}

void enqueue(queue *q,bitnode *x)
{
if((q->rear+1)%max==q->front)
{
printf("队列已满\n");
}

q->data[q->rear]=x;
q->rear=(q->rear+1)%max;

}

bitree dequeue(queue *q)
{
if((q->front+1)%max==q->rear)
{
printf("队列已空\n");
}
bitree T=q->data[q->front];
q->front=(q->front+1)%max;
return T;
}

void levelsort(bitree T)
{
queue q;
initqueue(&q);
bitree p;
enqueue(&q,T);
while(!isempty(&q))
{
printf("%c ",T->data);
p=dequeue(&q);
if(p->lchild!=NULL)
{
enqueue(&q,p->lchild);
}
if(p->rchild!=NULL)
{
enqueue(&q,p->rchild);
}
}
}

void creatbitree(bitree *T)
{
char ch;
ch=getchar();
if(ch=='#')
{
*T=NULL;
}
else
{
(*T)=(bitnode *)malloc(sizeof(bitnode));
(*T)->data=ch;
(*T)->lchild=NULL;
(*T)->rchild=NULL;
creatbitree(&((*T)->lchild));
creatbitree(&((*T)->rchild));
}
}

int main()
{
bitree T;
creatbitree(&T);
levelsort(T);
return 0;
}

hi, 我来了


printf("%c ",T->data);
p=dequeue(&q);
这两句改成,写反了
p=dequeue(&q);
printf("%c ",p->data);


改了后下面是输出 现在有点对了,还差点,在调调
AB#D##C##
队列已空
A B C 队列已空
D


应该是对了,因为在入队出队的过程中打印的正常,现在输出是 A B C D

不知道你这个问题是否已经解决, 如果还没有解决的话:

如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^