我在这两种结构:传递一个新节点的指针结构内
typedef struct node {
int info;
struct node *left, *right;
}NODE;
typedef struct bst {
NODE *root;
}BST;
而这些功能:
NODE *newNode(int info) {
NODE *tmp = (NODE *)malloc(sizeof(NODE));
tmp->left = tmp->right = NULL;
tmp->info = info;
return tmp;
}
void addTree(BST **bst, int info) {
if (*bst == NULL) {
(*bst)->root = newNode(info); // <- Breaks the program
return;
}
else while ((*bst)->root != NULL) {
if (info < (*bst)->root->info)
(*bst)->root = (*bst)->root->left;
if (info >(*bst)->root->info)
(*bst)->root = (*bst)->root->right;
}
(*bst)->root->info = info; // <- Breaks the program
}
我想不出有什么我已经做错了。 我打电话这样的功能的主要功能:
addTree(&binST, tmp);
我用调试器,它给了我不是一个单一的错误或警告。 任何帮助,将不胜感激。
' - >'也是一个解引用运算符,并且不能解引用NULL。 – jxh