当前位置:网站首页>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三
边栏推荐
- 记录一下MySql update会锁定哪些范围的数据
- 点的螺旋距离
- Selection (025) - what is the output of the following code?
- Laravel scheduled task
- 【js】-【数组应用】-学习笔记
- InnoDB, the storage engine of MySQL Architecture Principle_ Redo log and binlog
- 伪原创智能改写api百度-收录良好
- HarmonyOS访问数据库实例(3)--用ORM Bee测下HarmonyOS到底有多牛
- Selection (027) - what is the output of the following code?
- [JS] - [linked list - application] - learning notes
猜你喜欢

【js】-【栈、队-应用】-学习笔记

EMI的主要原因-工模电流

Super detailed cookie addition, deletion, modification and query

案例解析:用「度量」提升企业研发效能|ONES Talk

Blogs personal blog project details (servlet implementation)

#22Map介绍与API

Record the range of data that MySQL update will lock

【js】-【数组应用】-学习笔记

Laravel pagoda security configuration

Dig deep into MySQL - resolve the non clustered index of MyISAM storage engine
随机推荐
Financial management [2]
【js】-【栈、队-应用】-学习笔记
379. hide and seek
[JS] - [array application] - learning notes
【js】-【数组应用】-学习笔记
Selection (026) - what is the output of the following code?
第六章 网络学习相关技巧5(超参数验证)
Écoutez le fichier markdown et mettez à jour Hot next. Page JS
03_ Spingboot core profile
Fibonacci
No main manifest attribute in jar
docker-mysql8-主从
R语言使用MatchIt包进行倾向性匹配分析、使用match.data函数构建匹配后的样本集合、通过双样本t检验分析(双独立样本t检验)来判断倾向性评分匹配后样本中的所有协变量的平衡情况
laravel 验证器的使用
Financial management [1]
376. Tâches mécaniques
Gocolly manual
jar中没有主清单属性
Financial management [4]
sql -CONVERT函数