0
我想知道这个错误为什么它被占领了!来自C++的BST代码
class node
{
public:
int data ;
node *left ;
node *right ;
} ;
class tree
{
public:
node * root ;
public:
tree()
{
root = NULL ;
}
node* Insert(node* root, int num) //
{
if(root == NULL) // root is null
{
node * temp = new node() ;
temp->left = NULL ;
temp->right = NULL ;
temp->data = num ;
root = temp ;
}
else if (num < root->data)
{
root->left = Insert(root->left, num) ;
}
else if (num > root->data)
{
root->right = Insert(root->right, num) ;
}
return root ;
}
} ;
void main()
{
tree * Tree = new tree() ;
Tree->Insert(Tree->root, 10) ;
cout << temp->root->data ;
}
当我执行这个代码,比我预期的根的数据是10 但实际上,根是空的。 为什么root null?
我不知道!!!!
请教我!!!