当前位置:网站首页>第五章 树和二叉树
第五章 树和二叉树
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;
}
边栏推荐
- When the interviewer asks you to write binarysort in two ways
- P2394 yyy loves Chemistry I
- 详解final、finally和finalize
- A classic JVM class loaded interview question class singleton{static singleton instance = new singleton(); private singleton() {}
- R语言使用car包中的avPlots函数创建变量添加图(Added-variable plots)、在图像交互中,在变量添加图中手动标识(添加)对于每一个预测变量影响较大的强影响点
- A strange execution plan. One table in the association query is not associated with any other tables
- Numpy array: join, flatten, and add dimensions
- Function sub file writing
- Application of X6 in data stack index management
- Summary of PMP learning experience
猜你喜欢
随机推荐
Matplotlib属性及注解
Interpretation of new products: realm launched GT neo2 Dragon Ball customized version
1181: integer parity sort
bad zipfile offset (local header sig)
Composite pattern
Numpy array: join, flatten, and add dimensions
This article explains in detail the difficult problems and solutions faced by 3D cameras
Unity loads AssetBundle resources from the server and writes them to local memory, and loads the downloaded and saved AB resources from local memory to the scene
虛擬機14安裝win7(圖教程)
股票开户用中金证券经理发的开户二维码安全吗?知道的给说一下吧
Au revoir! Navigateur ie, cette route Edge continue pour IE
Matplotlib attribute and annotation
01-分布式系统概述
dotnet 使用 Crossgen2 对 DLL 进行 ReadyToRun 提升启动性能
MySQL基础知识点总结
Redis sentinel cluster main database failure data recovery ideas # yyds dry goods inventory #
Function sub file writing
Threads and processes
Check whether the table contains rows SQL Server 2005 - check whether a table contains rows or not SQL Server 2005
【OpenCV 例程200篇】213. 绘制圆形









