-1

if I have this code :

#
node* search2(node **root, int val){
#
 
#
node* temp = *root;
#
if(temp -> value == val){
#
printf("found!\n");
#
printf("ang root nfaun ay nasa : %d \n", temp -> value);
#
printf("dapat tigil na.");
#
return temp;
#
}
#
 
#
if(temp -> left == NULL && temp -> right == NULL){
#
return NULL;
#
}else{
#
if(temp -> value > val){
#
search2(&(temp -> left), val);
#
}else{
#
search2(&(temp -> right), val);
#
}
#
}
#
}

what should I return? temp or *root? when I return temp, the value of the root doesn't change. I don't understand. thanks!

3
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by Nick Evan
1

Depends on what you're trying to do. With all the '#' signs and no formatting, the code is too hard to follow without some explanation. Plus you should always explain what you're doing and not force us to read, understand, digest, and debug your code. Remember, we didn't write it so we don't know it.

And use the PREVIEW button to make sure your post looks good.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.