
二叉树遍历的问题
#include<stdio.h>#include<string.h>#include<stdlib.h>structnode{chardata;structnode*l...
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
struct node{
char data;
struct node *lchild;
struct node *rchild;
};
void BuildBtree(struct node *root){
char ch=getchar();
getchar();
if(ch==' ')
root=NULL;
else{
root=(struct node*)malloc(sizeof(struct node));
root->data=ch;
printf("输入%c的左子树",ch);
BuildBtree(root->lchild);
printf("输入%c的右子树",ch);
BuildBtree(root->rchild);
}
}
void InOrder(struct node *root){
if(root!=NULL){
InOrder(root->lchild);
putchar(root->data);
InOrder(root->rchild);
}
}
int main(){
struct node *root;
printf("输入根节点:");
BuildBtree(root);
printf("中序遍历结果:");
InOrder(root);
return 0;
}
运行时自己终止了 怎么回事儿啊 展开
#include<string.h>
#include<stdlib.h>
struct node{
char data;
struct node *lchild;
struct node *rchild;
};
void BuildBtree(struct node *root){
char ch=getchar();
getchar();
if(ch==' ')
root=NULL;
else{
root=(struct node*)malloc(sizeof(struct node));
root->data=ch;
printf("输入%c的左子树",ch);
BuildBtree(root->lchild);
printf("输入%c的右子树",ch);
BuildBtree(root->rchild);
}
}
void InOrder(struct node *root){
if(root!=NULL){
InOrder(root->lchild);
putchar(root->data);
InOrder(root->rchild);
}
}
int main(){
struct node *root;
printf("输入根节点:");
BuildBtree(root);
printf("中序遍历结果:");
InOrder(root);
return 0;
}
运行时自己终止了 怎么回事儿啊 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询