I get the algorithm and how binary trees should work but this I don't get :
look at the basic binary tree insert function :
node* insert_in_tree(int number,node* p_tree) {
if(p_tree == 0) {
node* newNode = new node;
node->num = number;
node->p_left = 0;
node->p_right = 0;
return newNode;
}
if(number < p_tree->num) {
p_tree->p_left = insert_in_tree(number,p_tree->p_left);
}
else {
p_tree->p_right = insert_in_tree(number,p_tree->p_right);
}
return p_tree;
so from main :
int main()
int main()
{
node* tree_node = 0;
cin >> num;
insert_in_tree(num,tree_node);
}
I get the first call to the function, tree is equal to 0, it creates a new node and so on, but how does tree changes it value so its not 0 anymore. I just can't see it in code?