hi
i have a general question about a function that i'm using in a binary tree.
the function has to return the value of the father of the node containing the value n;
but if n is the value in the root, what should i return?
this function should return an int
If the values in the nodes are restricted to some subset of ints (e.g. INT_MIN is never stored on the tree), then you can return one of the forbidden values to indicate this condition (similar to how many functions of std::string return the special value std::string::npos)
Otherwise, you'd have to throw an exception, or, better, redesign.
For max search, yes, you could return INT_MIN as the special value.. or you could redesign to avoid getting called on null pointers in the first place.