当前位置:网站首页>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
- 01_ Getting started with the spingboot framework
- R语言使用epiDisplay包的aggregate函数将数值变量基于因子变量拆分为不同的子集,计算每个子集的汇总统计信息、自定义FUN参数为多个统计量函数名称的列表计算多个统计量
- #22Map介绍与API
- golang map clear
- Detailed explanation of online group chat and dating platform project (servlet implementation)
- 378. Knight placement
- QT to place the form in the lower right corner of the desktop
- Laravel authentication module auth
猜你喜欢

Epics record reference 2 -- epics process database concept

Record the range of data that MySQL update will lock

Pseudo original intelligent rewriting API Baidu - good collection

Main cause of EMI - mold current

Case analysis: using "measurement" to improve enterprise R & D efficiency | ones talk

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

EMI的主要原因-工模电流

慕思股份深交所上市:靠床垫和“洋老头”走红 市值224亿
![[JS] - [stack, team - application] - learning notes](/img/5b/b90ed8d3eb4fc0ab41c6ea8d092d0f.png)
[JS] - [stack, team - application] - learning notes

Uncover the secrets of Huawei cloud enterprise redis issue 16: acid'true' transactions beyond open source redis
随机推荐
【js】-【字符串-应用】- 学习笔记
Laravel 认证模块 auth
Record the range of data that MySQL update will lock
Websocket long link pressure test
Notes for laravel model
二分查找数组下标
记录一下MySql update会锁定哪些范围的数据
376. 机器任务
jar中没有主清单属性
What good smart home brands in China support homekit?
[JS] - [array application] - learning notes
376. machine tasks
15 lines of code using mathematical formulas in wangeditor V5
Detailed explanation of online group chat and dating platform project (servlet implementation)
golang convert json string to map
From client to server
[JS] - [array, Stack, queue, Link List basis] - Notes
Financial management [5]
07_ Springboot for restful style
【js】-【數組、棧、隊列、鏈錶基礎】-筆記