主题:我这个程序运行有问题高手帮我看看
本算法要采用一个队列q,先将二叉树根结点入队列,然后退队列,输出该结点;若它有左子树,便将左子树根结点入队列;若它有右子树,便将右子树根结点入队列,直到队列空为止。因为队列的特点是先进先出,从而达到按层次顺序遍历二叉树的目的
#define M 100
#define Null 0
typedef struct node
{ int data;
stuuct node *lchild, *rchild;
} bitree;
bitree *que[M];
int front=0, rear=0;
bitree *creat( )
{ bitree *t;
int x;
scanf (“%d”, &x);
if (x= =0)
t=Null;
else
{
t=malloc(sizeof(bitree));
t→data=x;
t→lchild=creat( );
t→rchild=creat( );
}
return t;
}
void inorder( t )
bitree *t;
{ if (t!=Null)
{ inorder (t→lchild);
printf(“%4d”, t→data);
inorder (t→rchild);
}
}
void enqueue(t)
bitree *t;
{ if(front!=(rear+1) % M)
{rear = (rear+1) % M;
que[rear]=t;
}
}
bitree *delqueue( )
{
if (front= =rear)
return Null;
front=(front+1) % M;
return (que[front]);
}
void levorder ( t )
bitree *t;
{ bitree *p;
if(t!=Null)
{enqueue( t );
while(front!=rear)
{ p=delqueue( );
printf(“%4d”, p→data);
if(p→lchild!=Null)
enqueue(p→lchild);
if(p→rchild!=Null)
enqueue(p→rchild);}
}
}
main ( )
{ bitree *root;
printf(“\n”);
root=creat ( );
inorder(root);
printf(“\n”);
levorder(root);
}
#define M 100
#define Null 0
typedef struct node
{ int data;
stuuct node *lchild, *rchild;
} bitree;
bitree *que[M];
int front=0, rear=0;
bitree *creat( )
{ bitree *t;
int x;
scanf (“%d”, &x);
if (x= =0)
t=Null;
else
{
t=malloc(sizeof(bitree));
t→data=x;
t→lchild=creat( );
t→rchild=creat( );
}
return t;
}
void inorder( t )
bitree *t;
{ if (t!=Null)
{ inorder (t→lchild);
printf(“%4d”, t→data);
inorder (t→rchild);
}
}
void enqueue(t)
bitree *t;
{ if(front!=(rear+1) % M)
{rear = (rear+1) % M;
que[rear]=t;
}
}
bitree *delqueue( )
{
if (front= =rear)
return Null;
front=(front+1) % M;
return (que[front]);
}
void levorder ( t )
bitree *t;
{ bitree *p;
if(t!=Null)
{enqueue( t );
while(front!=rear)
{ p=delqueue( );
printf(“%4d”, p→data);
if(p→lchild!=Null)
enqueue(p→lchild);
if(p→rchild!=Null)
enqueue(p→rchild);}
}
}
main ( )
{ bitree *root;
printf(“\n”);
root=creat ( );
inorder(root);
printf(“\n”);
levorder(root);
}