Tree Build(Tree &t){
char ch[4];
int num;
scanf("%s",ch);
scanf("%d",&num);
count++;
if(ch[1]=='u'){
t=(Tree)malloc(sizeof(struct TreeNode));
t->data=num;
t->left=NULL;
t->right=NULL;
if(count<=2*n){
Build(t->left);
}
if(count<=2*n){
Build(t->right);
}
}
if(ch[1]=='o'){
if(count<=2*n){
t=NULL;
}
}
return t;
}
Tree是一个指针,指向一个节点,,我不知道该怎么表达,也不知道该怎么截图……
出现的错误是Access Violation
struct TreeNode{
int data;
struct TreeNode *left;
struct TreeNode *right;
};
typedef TreeNode * Tree;
这是结构体的定义
t=(Tree)malloc(sizeof(struct TreeNode));
到底是TreeNode还是Tree?
应该是Tree &t的错,
应定义指针的指针
Tree * t,
更改指针的指针
Build(t->left); 时 t->left 为空的,应该是: &t->left 才行吧。