bool roottoleafsumequaltox(BinaryTreenode<int>* root, int &x)
{
if(root == NULL)
{
return (x==0);
}
else
{
bool ans = false;
x = x - root->data;
if(x == 0 && root->left == NULL && root->right == NULL)
{
return true;
}
if(root->left)
ans = ans || roottoleafsumequaltox(root->left, x);
if(root->right)
ans = ans || roottoleafsumequaltox(root->right, x);
return ans;
}
}
Es muss zurückgegeben werden, ob die Summe von Wurzel zu Blat einer gegebenen Zahl x entspricht. Ich denke das Problem liegt darin, durch Verweis zu gehen und ich kann es nicht erkennen ... Es gibt immer falsch als Antwort, auch wenn es wahr ist!C++ - Übergabe durch Referenz in Rekursion