当前位置:网站首页>7-2 后序+中序序列构造二叉树
7-2 后序+中序序列构造二叉树
2022-06-24 19:43:00 【白—】
7-2 后序+中序序列构造二叉树
后序+中序序列构造二叉树
输入样例:
第一行输入序列长度n,第二行输入n个字符表示二叉树后序遍历的序列,第三行输入n个字符表示二叉树中序遍历的序列
9
GHDBEIFCA
GDHBAECIF
输出样例:
输出二叉树先序遍历的序列。
ABDGHCEFI
代码:
#include <stdio.h>
#include <stdlib.h>
int n;
void CreatTree(int n,char after[],char mid[])
{
if(n<0)
return ;
else
{
printf("%c",after[n]);
int i;
for(i=0;i<=n;i++)
{
if(mid[i]==after[n])
break;
}
CreatTree(i-1,after,mid);
CreatTree(n-i-1,after+i,mid+i+1);
return ;
}
}
int main()
{
char after[1000];
char mid[1000];
scanf("%d",&n);
scanf("%s",after);
scanf("%s",mid);
CreatTree(n-1,after,mid);
return 0;
}
202206222111三
边栏推荐
- [basic knowledge] ~ half adder & full adder
- Bubble sort
- R language uses the multinom function of NNET package to build an unordered multi classification logistic regression model, and uses the AIC function to compare the AIC values of the two models (simpl
- Still using simpledateformat for time formatting? Be careful of project collapse
- R语言使用nnet包的multinom函数构建无序多分类logistic回归模型、使用AIC函数比较两个模型的AIC值的差异(简单模型和复杂模型)
- 監聽 Markdown 文件並熱更新 Next.js 頁面
- golang convert json string to map
- 慕思股份深交所上市:靠床垫和“洋老头”走红 市值224亿
- F29oc analysis
- 去处电脑桌面小箭头
猜你喜欢

文件包含漏洞问题
![[JS] - [array application] - learning notes](/img/8a/808fde0cc86e0ec5e1f5558ba196b4.png)
[JS] - [array application] - learning notes

#22Map介绍与API

Pseudo original intelligent rewriting API Baidu - good collection

Concurrent shared model management

Jetpack Compose 最新进展

【js】-【數組、棧、隊列、鏈錶基礎】-筆記

Dig deep into MySQL - resolve the non clustered index of MyISAM storage engine

Online group chat and dating platform test point

还在用 SimpleDateFormat 做时间格式化?小心项目崩掉
随机推荐
Uncover the secrets of Huawei cloud enterprise redis issue 16: acid'true' transactions beyond open source redis
Financial management [3]
websocket学习
378. Knight placement
golang convert json string to map
Selection (027) - what is the output of the following code?
Mycms we media CMS V3.0, resource push optimization, new free template
Use of laravel verifier
. Net 7 Preview 1 has been officially released
Super detailed cookie addition, deletion, modification and query
laravel 创建 service层
R语言使用epiDisplay包的aggregate函数将数值变量基于因子变量拆分为不同的子集,计算每个子集的汇总统计信息、自定义FUN参数为多个统计量函数名称的列表计算多个统计量
Paddledtx v1.0 has been released, and its security and flexibility have been comprehensively improved!
Blogs personal blog test point (manual test)
[JS] - [stack, team - application] - learning notes
文件包含漏洞问题
Chapter VI skills related to e-learning 5 (super parameter verification)
Ganglia 的安装与部署
Financial management [1]
Laravel message queue