二叉链表存储结构的问题
#include "whead.h"#include <stdio.h>
#include <malloc.h>
#include <iostream>
#define MAX_TREE_SIZE 100
typedef char TElemType;
//typedef TElemType SqBiTree[MAX_TREE_SIZE];
typedef struct BiTreeNode {
TElemType data;
struct BiTreeNode *lchild;
struct BiTreeNode *rchild;
}BiTreeNode, *BiTree;
BiTree tm;
Status visit(TElemType v) {
printf("node==", v);
printf("\n");
return OK;
}
Status createBiTreePre(BiTree t) {
char ch;
printf("Input char :");
scanf("%c" ,&ch);
printf("\n");
if(ch == ' ')
t = NULL;
else {
if(!(t = (BiTreeNode*)malloc(sizeof(TElemType))))
exit(OVERFLOW);
t->data = ch;
createBiTreePre(t->lchild);
createBiTreePre(t->rchild);
}
return OK;
}
Status traversePre(BiTree t, Status (*visit)(TElemType e)) {
if(t){
if(t->data)
if(traversePre(t->lchild, visit))
if(traversePre(t->rchild,visit))
return OK;
return ERROR;
}
else
return OK;
}
#include "BinaryTree.h"
void main() {
createBiTreePre(tm);
traversePre(tm, visit);
}
为什么第一次createBiTreePre(t->lchild)无法输入,第二次就可以,第三次又不行。。。。。以此类推