当前位置:网站首页>Chapter 5 trees and binary trees
Chapter 5 trees and binary trees
2022-06-28 09:58:00 【Zhong Zhongzhong】
The basic concept of tree
1. The number of words owned by a node is called the degree of the node ; The maximum degree of each node in a tree is called the degree of the tree .
2. The number of sides on the path is the path length .
3. Specify the number of layers of the root node as 1, The maximum number of levels of all nodes in a tree is called the depth of the tree ; The maximum number of nodes in each layer in the book is called the width of the tree .
Be careful : In order to uniquely determine a binary tree, there must be a middle order in two sequences .
Determine a tree according to its front order and middle order :
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;
}
Determine the height of the tree :
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;
}
边栏推荐
- Correct conversion between JSON data and list collection
- 标识符的命名规则和规范
- ffmpeg录音录像
- Flip CEP skip policy aftermatchskipstrategy Skippastlastevent() matched no longer matches the Bikeng Guide
- 满电出发加速品牌焕新,长安电动电气化产品吹响“集结号”
- R language plot visualization: plot to visualize overlapping histograms, and use geom at the bottom edge of the histogram_ The rugfunction adds marginal rugplots
- Unity AssetBundle资源打包与资源加载
- Au revoir! Navigateur ie, cette route Edge continue pour IE
- 六月集训(第28天) —— 动态规划
- PMP考试重点总结七——监控过程组(1)
猜你喜欢

Starting from full power to accelerate brand renewal, Chang'an electric and electrification products sound the "assembly number"

HDI的盲孔设计,你注意到这个细节了吗?

PMP考试重点总结八——监控过程组(2)

布隆过滤器 课程研究报告

组合模式(Composite Pattern)

装饰模式(Decorator)

Why does istio use spirit for identity authentication?

Composite pattern

【OpenCV 例程200篇】213. 绘制圆形

桥接模式(Bridge)
随机推荐
Dotnet uses crossgen2 to readytorun DLL to improve startup performance
PMP Exam key summary IX - closing
JVM系列(2)——垃圾回收
01 distributed system overview
abnormal
Unity AssetBundle asset packaging and asset loading
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
Importerror: no module named image [duplicate] - importerror: no module named image [duplicate]
Differences between task parameter types inout and ref
Data visualization makes correlation analysis easier to use
用 Compose 实现个空调,为你的夏日带去清凉
TCP实战案例之即时通信、BS架构模拟
微信小程序开发日志
Au revoir! Navigateur ie, cette route Edge continue pour IE
Regular verification of mobile phone number and email [easy to understand]
Composite pattern
Dbeaver connects to kingbasees V8 (ultra detailed graphic tutorial)
Settings of gift giving module and other custom controls in one-to-one video chat system code
优秀笔记软件盘点:好看且强大的可视化笔记软件、知识图谱工具Heptabase、氢图、Walling、Reflect、InfraNodus、TiddlyWiki
ffmpeg录音录像