Yes the node store their depth. The binary in my program have these number(28,125,22,23,21,19). The deepest mean print the deepest level which is 21 only.
U * foo( U * node ) {
if ( ! node ) returnnullptr;
auto left = foo( node->left );
auto right = foo( node->rigth );
if ( left && right ) {
return ( left->depth < right->depth ) ? right : left;
}
elseif ( left ) return left;
elseif ( right ) return right;
elsereturn node;
}
template <class T>
bool BST<T>::deepestNode()
{
auto deep = foo( root );
if ( deep ) std::cout << *deep;
return deep;
}