我想定义一个函数,使二叉搜索树为空,返回类型为VALID.
以下是我的代码:
_Node structure
个
typedef struct _Node {
int data;
struct _Node* l_child;
struct _Node* r_child;
} Node;
BST_To_Empty
个
void BST_To_Empty(Node* root)
{
if(root)
{
BST_To_Empty(root->l_child);
BST_To_Empty(root->r_child);
free(root);
}
printf("[BST_To_Empty] Now BST is NULL");
}
CheckEmpty
个
void isEmpty(Node* root)
{
if (root == NULL)
{
printf("NULL");
}
else
{
printf("Not NULL");
}
}
使用这些代码,我的主要功能如下:
int main()
{
Node* root = NULL;
// Some Initialization
BST_To_Empty(root);
CheckEmpty(root);
}
所以我想我可以得到一个结果, "[BST_TO_EMPTY]现在BST为空"和 "空"
但我有 "[BST_TO_EMPTY]现在BST为空"和 "非空"
我有点困惑,为什么"CheckEmpty"的结果是"Not Null"虽然 我免费做了根?
我应该修改什么才能得到"CheckEmpty"为"Null"的结果?
谢谢你的帮助.