/*internal method to test if an item is in subtree is item to search for is the node that roots the subtree *bool containsconst comparable xbinarynode * const ift =nullptr return falseelse ifx element return containsxt->left )else ift->element return containsxt->right )else return true/match figure contains operation for binary search trees notice the order of the tests it is crucial that the test for an empty tree be performed firstsince otherwisewe would generate run time error attempting to access data member through nullptr pointer the remaining tests are arranged with the least likely case last also note that both recursive calls are actually tail recursions and can be easily removed with while loop the use of tail recursion is justifiable here because the simplicity of algorithmic expression compensates for the decrease in speedand the amount of stack space used is expected to be only (log nfigure shows the trivial changes required to use function object rather than requiring that the items be comparable this mimics the idioms in section findmin and findmax these private routines return pointer to the node containing the smallest and largest elements in the treerespectively to perform findminstart at the root and go left as long as there is left child the stopping point is the smallest element the findmax routine is the sameexcept that branching is to the right child many programmers do not bother using recursion we will code the routines both ways by doing findmin recursively and findmax nonrecursively (see figs and notice how we carefully handle the degenerate case of an empty tree although this is always important to doit is especially crucial in recursive programs also notice that it is safe to change in findmaxsince we are only working with copy of pointer always be extremely carefulhoweverbecause statement such as ->right ->right->right will make changes