This codeblock comes from Mr Weiss's book "Data Sturucture and Algorithm Analysis in C++"(Third Edition). I have some questions about it.
/**
*This is a member function from the BinarySearchTree class.
*And It try to find whether there's a element equal to x in
*the binary search tree.
*/
bool BinarySearchTree::contains(const int & x, BinaryNode *t){
if(t==NULL)
return false;
/**
*Weiss put the following two sentences to the end of this
*codeblock with an "else".But I think put it here can make
*the code more readable.Is it an error?
*/
if(x == t->element)
return true;
/**
*When I implemented these, I haven't added
*"return" before recursive functions.
*Why must add "return" in the following sentences?
*How many times will the "return" really
*return when the promgram run?
*What will be happened,if I delete these "return"?
*/
if(x < t->element)
return contains(x,t->left);
else if(t->element < x )
return contains(x,t->right);
}
My questions have put in the codeblock.I know that my English is bad,if you find some errors in my English syntax,please help me too! As you know,it's impossible to study C++ well without English.
Thanks ^_^