根据扩展二叉树前序序列生成二叉树,输入某个节点的值,查找其双亲节点的值(二叉链表)
来源:互联网 发布:python编程 编辑:程序博客网 时间:2024/05/16 07:07
#include <iostream>
#include <string>
using namespace std;
struct BiNode{
char ch;
BiNode * Left;
BiNode * Right;
};
BiNode * root=NULL;
void Create(BiNode * & root)
{
char ch;
cin>>ch;
if(ch=='#')
{
root=NULL;return;
}
root=new BiNode;
root->ch=ch;
Create(root->Left);
Create(root->Right);
}
void FindParent(BiNode * & result,BiNode * root,BiNode * pre,char son)
{
if(root==NULL)
return;
if(root->ch==son)
{
result=pre;return;
}
if(!result)
FindParent(result,root->Left,root,son);
if(!result)
FindParent(result,root->Right,root,son);
}
void main()
{
Create(root);
BiNode * result=NULL;
FindParent(result,root,NULL,'A');
cout<<"Parent: "<<result->ch;
::system("pause");
#include <string>
using namespace std;
struct BiNode{
char ch;
BiNode * Left;
BiNode * Right;
};
BiNode * root=NULL;
void Create(BiNode * & root)
{
char ch;
cin>>ch;
if(ch=='#')
{
root=NULL;return;
}
root=new BiNode;
root->ch=ch;
Create(root->Left);
Create(root->Right);
}
void FindParent(BiNode * & result,BiNode * root,BiNode * pre,char son)
{
if(root==NULL)
return;
if(root->ch==son)
{
result=pre;return;
}
if(!result)
FindParent(result,root->Left,root,son);
if(!result)
FindParent(result,root->Right,root,son);
}
void main()
{
Create(root);
BiNode * result=NULL;
FindParent(result,root,NULL,'A');
cout<<"Parent: "<<result->ch;
::system("pause");
}
测试输入:BC##DEA##F##G##
输出:Parent: E
- 根据扩展二叉树前序序列生成二叉树,输入某个节点的值,查找其双亲节点的值(二叉链表)
- java 二叉树(六)查找二叉树一个节点的双亲节点
- 查找二叉搜索树中小于某个节点的最大值
- 二叉查找树(3) - 查找值最小的节点
- 如何找到二叉树两个节点的最近公共双亲?
- 二叉查找树面试题——计算每个节点的比其值大的节点和
- 树-二叉树中某个节点的下一个节点
- 打印二叉树中某个节点的所有父节点
- 找出二叉树中某个节点的所有祖先节点
- 找出二叉树中某个节点的所有祖先节点
- 查找二叉树节点
- 查找二叉树删除节点的操作
- 二叉查找树中节点的删除。
- 二叉树公共祖先节点的查找
- 删除二叉查找树的节点-LintCode
- 检测二叉查找树节点的情况
- 删除二叉查找树的节点
- 删除二叉查找树的节点
- 跟Google学习Android开发-起始篇-与其它应用程序交互(3)
- Jenkins 回显
- MXML语法基础
- android sdcard下创建文件夹
- 我的第一个Selenium2
- 根据扩展二叉树前序序列生成二叉树,输入某个节点的值,查找其双亲节点的值(二叉链表)
- ZAKER
- 杨辉三角
- 专访沈逸:技术,不存在有前途没前途之分
- annotation
- Ubuntu上Eclipse不识别Android手机的解决方法
- aries blueprint资料收集
- 最近在使用MyEclipse的SVN插件时总是弹出一个大大的对话框,报一个Failed to load JavaHL Library.错误
- vim 虎の巻