当前位置:网站首页>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三
边栏推荐
猜你喜欢
Concurrent shared model management
15 lines of code using mathematical formulas in wangeditor V5
[JS] - [array application] - learning notes
[basic knowledge] ~ half adder & full adder
伪原创智能改写api百度-收录良好
选择类排序法
Dig deep into MySQL - resolve the clustered index / secondary index / federated index of InnoDB storage engine
Jetpack Compose 最新进展
文件包含漏洞问题
Main cause of EMI - mold current
随机推荐
Case analysis: using "measurement" to improve enterprise R & D efficiency | ones talk
OpenSSL SSL_ read: Connection was reset, errno 10054
点的螺旋距离
Selection (029) - what is the output of the following code?
03_ Spingboot core profile
379. hide and seek
Financial management [1]
Financial management [5]
从客户端到服务器
Laravel creates a service layer
Dig deep into MySQL - resolve the non clustered index of MyISAM storage engine
[JS] - [stack, team - application] - learning notes
Building Survey [3]
力扣解法汇总515-在每个树行中找最大值
Common regular expressions
laravel 消息队列
Websocket learning
golang convert map to json string
[introduction to UVM== > episode_8] ~ sequence and sequencer, sequence hierarchy
Detailed explanation of online group chat and dating platform project (servlet implementation)