在二叉树中找到最低的叶子
Find the lowest leaf in a binary tree
我正在尝试比较所有叶以返回树的最低值,我没有主函数,只有一个插入值的脚本,所以很遗憾我无法调试它。
tpNoArvore * findLowest(tpNoArvore * pNo){
tpNoArvore * left;
tpNoArvore * right;
tpNoArvore * res;
if (!pNo) return NULL; /* if */
left = findLowest(pNo->pNoL);
right = findLowest(pNo->pNoR);
if(isLeaf(pNo))
return pNo;
} /* if */
if(!left){
return right;
} /* if */
if(!right){
return left;
} /* if */
return (left->Valor < right->Valor) ? left : right ;
}
所以,基本上,我在这里试图实现的是比较每个节点的两侧,找到最低的。
您的代码返回指针似乎很奇怪。我希望有这样的东西:
// Assume valor is int
int findLowest(tpNoArvore * pNo){
if (!pNo) exit(1); /* fatal error */
// If this is a leaf just return its value
if(isLeaf(pNo)) return pNo->Valor;
// Not a leaf
// Find the lowest value in left part of tree
int leftValor = findLowest(pNo->pNoL);
// Find the lowest value in right part of tree
int rightValor = findLowest(pNo->pNoR);
// Return the lowest of leftValue ans rightValue
return (leftValor < rightValor) ? leftValor : rightValor ;
}
但也许我误解了你的问题。
相关文章:
- 从父数组测试用例构造二叉树失败
- 打印时有二叉树问题.用户输入不打印任何内容
- 试图找到二叉树的深度
- 二叉树结构平衡,使用递归时EXC_BAD_ACCESS
- 指向二叉树中新节点的指针
- 我试图用这段代码找到二叉树的高度,但它一直返回 0,有人可以告诉我为什么吗?
- C++:如何计算二叉树中其值模块高度小于 2 的节点数?
- 二叉树级别顺序遍历在leetcode中
- 运行无限循环的最小二叉树问题
- 打印二叉树中的常见元素
- 二叉树基准测试结果
- 带有矢量重复值的二叉树打印出来
- 签入二叉树的函数是平衡C++
- 我有两棵二叉树.我想在不更改输入树的情况下深度复制两个二叉树的结果
- 如何计算给定数字在二叉树中出现的次数?
- 为什么我的二叉树会覆盖其根的叶子?
- 如何获取二叉树代码上的叶子数量
- 在二叉树中找到最低的叶子
- C++ 二叉树:返回节点的后代数.一片叶子有零.如果未找到树数据,则返回 -1
- 如何构建从叶子到根的二叉树