当前位置:网站首页>第五章 树和二叉树
第五章 树和二叉树
2022-06-28 09:40:00 【钟钟终】
树的基本概念
1.某节点所拥有的字数的个数称为该节点的度;树中各节点度的最大值称为树的度。
2.路径上经过的边数为路径长度。
3.规定根节点的层数为1,树中所有节点的最大层数称为树的深度;书中每一层结点个数的最大值称为树的宽度。
注意:两个序列中必须有一个中序才能唯一确定一棵二叉树。
根据树的前序和中序确定一棵树:
Binode* Create_pre(char *pre,char *mid,int ipre,int imid,int n)
{
if(n==0)
return NULL;
Binode *p=new Binode;
p->data=pre[ipre];
int i=0;
while(pre[ipre]!=mid[imid+i]) i++;
p->lc=Create_pre(pre,mid,ipre+1,imid,i);
p->rc=Create_pre(pre,mid,ipre+i+1,imid+i+1,n-i-1);
return p;
}
确定树的高度:
int Height(Binode* p)
{
if(p==NULL)
return 0;
int left,right;
left=Height(p->lc);
right=Height(p->rc);
if(left>right)
return left+1;
else
return right+1;
}
边栏推荐
- 创建多线程的方法---1创建Thread类的子类及多线程原理
- 再見!IE瀏覽器,這條路由Edge替IE繼續走下去
- Installing redis under Linux and windows (ultra detailed graphic tutorial)
- 如图 用sql行转列 图一原表,图二希望转换后
- Differences between task parameter types inout and ref
- 纵观jBPM从jBPM3到jBPM5以及Activiti
- Thread lifecycle
- Global exception handlers and unified return results
- R语言使用car包中的avPlots函数创建变量添加图(Added-variable plots)、在图像交互中,在变量添加图中手动标识(添加)对于每一个预测变量影响较大的强影响点
- 大纲笔记软件 Workflowy 综合评测:优点、缺点和评价
猜你喜欢

new URL(“www.jjj.com“)

PyGame game: "Changsha version" millionaire started, dare you ask? (multiple game source codes attached)

如何查看谷歌浏览器保存的网页密码

Dbeaver installation and use tutorial (super detailed installation and use tutorial)

How to reduce the risk of project communication?

全局异常处理器与统一返回结果

Au revoir! Navigateur ie, cette route Edge continue pour IE

How to view the web password saved by Google browser

Linux下安装redis 、Windows下安装redis(超详细图文教程)

The concept of "tree structure" perfectly interprets the primary and secondary of things
随机推荐
Regular verification of mobile phone number and email [easy to understand]
Edit the live broadcast source code with me. How to write the live broadcast app code
Huawei OSPF single region
满电出发加速品牌焕新,长安电动电气化产品吹响“集结号”
2022-06-27:给出一个长度为n的01串,现在请你找到两个区间, 使得这两个区间中,1的个数相等,0的个数也相等, 这两个区间可以相交,但是不可以完全重叠
The constructor is never executed immediately after new()!!!!!
小米旗下支付公司被罚 12 万,涉违规开立支付账户等:雷军为法定代表人,产品包括 MIUI 钱包 App
How to view the web password saved by Google browser
This article explains in detail the difficult problems and solutions faced by 3D cameras
Au revoir! Navigateur ie, cette route Edge continue pour IE
JVM系列(2)——垃圾回收
Adapter mode
MySQL基础知识点总结
For the development of short video app, the elder warned me to choose the open source code
全局异常处理器与统一返回结果
1181: integer parity sort
JDBC connection database (MySQL) steps
English translation plug-in installation of idea
JVM family (2) - garbage collection
Decorator