首页 > 解决方案 > 即使我有一个cout,它也不会回来

问题描述

由于某种原因,它似乎没有返回任何东西有人能指出我正确的方向吗这是我的代码计数离开函数

template<class T>
int BinaryTree<T>::leaves(TreeNode* n)
{
    int count = 0;
    if (n->left == NULL && n->right == NULL)
        count++;
    else
    {
        if (n->left != NULL)
        count += leaves(n->left);
        if (n->right != NULL)
        count += leaves(n->right);
    }

    return count;

}

该函数的吸气剂

template<class T>
int BinaryTree<T>::numLeaves()
{
    return leaves(root);
}

和主要

case 6:
                cout << "The total number of leaves are " << tree.numLeaves() << endl;
                break;

出于某种原因,一切似乎都在工作,因为它不会使代码崩溃,但它不会返回任何东西,例如,如果我输入 5 4 2 9 0 它应该返回 2,其中“2”和“9”是叶子,但它没有没有人可以向我解释什么是错的

标签: c++debugging

解决方案


推荐阅读