void instert(NODE**root, int value)
{
...
insert(&(*root)->left,value);
...
}
void search(NODE*root, int value)
{
...
search(root->left, value);
...
}
Why we use "&" here: insert(&(*root)->left,value); But we do not use "&" here: search(root->left, value);
&(*
isn't a statement.It is parts of the
&
-operator being applied to the expression(*root)->left
.An extra level of indirection is added to
insert
function so that it could modify the pointer. This is not necessary in case of thesearch
function, because it never modifies the pointer passed to it.Specifically, there needs to be a place in the
insert
function that does something like this:This would modify the pointer which is pointed to by the pointer to pointer.
Note that it is possible to avoid this extra level of indirection by returning the new value of the pointer from
insert
, like this:However, this changes the way in which all callers must call
insert
, including the top-level caller: rather than writinghe would be forced to write
The expression:
Is equivalent to:
Due to operator precedence.
So you need:
If you want the
left
member that*root
points to.And then:
Is the pointer to the
left
member of*root
, which is then of typeNODE **
, what theinsert
function requires.