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;
}
}
ルートからリーフまでの合計が与えられたxと等しいかどうかを返す必要があります。私は問題が参照渡しにあると思うし、私はそれを検出できません... それは本当であるとしても、それは常に答えとして偽を与える!C++再帰で参照渡し