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!

Recommended Answers

All 2 Replies

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.

Double thread with this. Closed

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.