So I'm writing this height function of an avl tree class :
int avlTree::height(avlNode* tree) {
if (!tree) {
throw invalidInput;
}
if (!tree->left && !tree->right) {
return 0;
}
return max(height(tree->right), height(tree->left)) + 1;
}
But It feels like something is wrong, I thought of implementing it in such a way that in the beginning the tree will be checked for NULL and if it is, a 0 should be returned. But then I lose the possibiilty to check if the tree was a void pointer in the first place. Or is it fine that it'll return 0 even if it's a void pointer? what's more accepted?
thanks!