输出二叉树中随机两个结点的最小公共父结点
来源:互联网 发布:淘宝异常订单处理中心 编辑:程序博客网 时间:2024/05/18 02:11
思路:当遇到一个结点是返回1,当左右子树都返回1的时候,即最小公共父节点。
//二叉树的数据结构typedef struct MyStruct{ char data; struct MyStruct *leftChild; struct MyStruct *rightChild;}Node, *Tree;//查找方法int findFirstFather(Tree root, char first, char second,char &destination){ int i, j; if (root==NULL) { return 0; } if (root->data == first || root->data == second) { return 1; } else { i = findFirstFather(root->leftChild, first, second, destination); j = findFirstFather(root->rightChild, first, second, destination); if (i == 1 && j == 1) { destination = root->data; } if (i||j) { return 1; } } return 0;}输入:ABC##DE#G##F###输出:D
0 0
- 输出二叉树中随机两个结点的最小公共父结点
- 二叉树中两个结点的最低公共祖先
- 满二叉树中任意两个结点的公共祖先
- 求二叉树中两个结点的最近公共祖先
- 二叉树两个结点的最低公共父结点 【微软面试100题 第七十五题】
- 二叉树两结点的最低公共父结点
- 题目:在二叉树中给出两个已知结点,求这两个结点的最低公共祖先
- 二叉树中找两个结点的最近的公共祖先结点
- 二叉树中找两个结点的最近公共祖先结点
- 二叉树中找两个结点的最近公共祖先结点
- 二叉树------寻找二叉树中两个结点的最近公共祖先
- 二叉树中两个结点的距离
- 二叉树中两个结点的距离
- 二叉树两个结点的最低公共祖先
- 二叉树两个结点的最低公共祖先
- 二叉树两个结点的最低共同父结点
- 二叉树两个结点的最低共同父结点【算法】
- 二叉树两个结点的最低共同父结点
- Latent Dirichlet Allocation(LDA)主题模型算法实现及源码解析
- 黑马程序员——集合类(2)
- LDA(Latent Dirichlet Allocation)主题模型算法
- makefile详细用法
- Latent dirichlet allocation note
- 输出二叉树中随机两个结点的最小公共父结点
- C语言中printf直接打出2进制数是%什么?16进制是什么?
- 黑马程序员——IO流
- iOS之代码混淆
- HDU 1402 A * B Problem Plus FFT
- VB.NET 章鱼哥 如何在项目中使用外部文字格式
- 列表checkbox效果
- Binary Tree Level Order Traversal
- 黑马程序员——网络编程