作者热门文章
- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我需要编写操作来计算具有两个彼此相等的儿子的节点。我试过了,但出现错误,并非所有代码路径都返回一个值。请帮我做个测试谢谢。
public static int CountWhoHasTwoSameSons(BinNode<int> Head)
{
if (Head != null)
{
if (IsLeaf(Head))
return 1;
if ((Head.HasLeft() && Head.HasRight()) && (Head.GetRight() == Head.GetLeft()))
return 1 + CountWhoHasTwoSameSons(Head.GetLeft()) + CountWhoHasTwoSameSons(Head.GetRight());
}
}
static void Main(string[] args)
{
BinNode<int> t = new BinNode<int>(3);
BinNode<int> t1 = new BinNode<int>(3);
BinNode<int> t2 = new BinNode<int>(3);
BinNode<int> t3 = new BinNode<int>(3);
BinNode<int> t4 = new BinNode<int>(t,3,t1);
BinNode<int> t5 = new BinNode<int>(t2,3,t3);
BinNode<int> t6 = new BinNode<int>(t4,3,null);
BinNode<int> Head = new BinNode<int>(t6,3,t5);
Console.WriteLine(SumTree(Head));
Console.WriteLine(LeafCounter(Head));
Console.WriteLine(CountWhoHasTwoSameSons(Head));
Console.ReadLine();
}
最佳答案
您需要在 If 语句外添加一个 return,编译器无法确定此函数是否会返回某些内容。如果您可以在返回 0 的函数末尾添加一个 return 语句,它应该可以工作。不是最喜欢的修复方法,您应该真正重写函数,这样返回实际上不仅仅是一种取悦编译器的方式,但它应该可以工作。
丹尼
关于c# - 计算有两个相同儿子的节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43019896/
我正在使用 Iris 数据进行配对。但是历史图看起来真的很难看(例如左上图),我怎样才能添加边缘颜色(白色)以使其更清晰? 我使用的代码是这样的: sns.pairplot(df, hue="Spec
我需要在他的笔记本电脑上安装一个 c# ide(免费),我需要下载 sdk 还是 windows 7 带有 c# 编译器? (从头开始设置已经有一段时间了) 最佳答案 你可以试试Visual C# 2
我是一名优秀的程序员,十分优秀!