二叉树中特定节点的高度
Height of particular node in a binary tree
int finddepth(Node *node,int key)
{
if(node==NULL)
return 0;
if(node->data==key)
return 1;
return max(depth(node->left),depth(node->right));
}
我只想计算一个特定节点的高度或深度。如何增加深度。我知道这个程序总是返回1
我认为没有必要让你变得复杂,你可以尝试以下代码
int finddepth(Node* root)
{
if(root==NULL)
return 0;
int l=finddepth(root->left);
int r=finddepth(root->right);
if(l>r)
return l+1;
return r+1;
}
相关文章:
- 反向给定链表中的K节点
- 如果我只是不访问queue_front节点的子节点,而是将它们推到队列中呢?还是BFS吗
- Boost Graph Library,修复节点大小
- C++A*算法并不总是在路径中具有目标节点
- 如何找到2个单链表的公共节点
- 计算每个节点的树高,帮助我解释这个代码解决方案
- 为什么我的删除节点函数实际上没有删除节点?
- 我们可以删除链表中静态内存中的节点吗
- 如何在pugixml中获取节点的内部XML
- 为什么我们要为avl树实现返回一个指向节点的指针,而不是void函数
- C++RapidXml-使用first_node()遍历以修改XML文件中节点的值
- 为什么C++对链表中的下一个节点使用指针,而像 C# 或 Java 这样的语言只使用类 Node 的名称?
- C++17 - 使用自定义分配器的节点提取/重新插入 - 适用于 clang++/libc++,但不适用于 libstd
- 节点 *temp; 和节点 *tmp = 新节点之间的差异
- 接受来自键盘的树节点以确定其高度
- C ,二进制树的高度,而不是检查我的子树是否为空,而是在检查我的子树是否是叶子节点.抛出分割故障
- 找到任何节点的BST高度
- BST设置每个指向节点的高度
- 在一棵有191个节点且高度为9的二叉树中找到一个键所需的最大比较次数是多少?
- 二叉树中特定节点的高度