#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include
using namespace std;
char mid[100];
char late[100];
void creat(int post_mid,int post_late,int k)//post_mid:中序开头位置,post_late后序开头位置,k序列长度//
{
int i;
if(k<=0)
{
return;
}
cout<<late[post_late+k-1];
i=post_mid;
while(late[post_late+k-1]!=mid[i])//中序中寻找根结点//
{
i++;
}
int left_num=i-post_mid;
int right_num=k-left_num-1;
creat(post_mid,post_late,left_num);
creat(post_mid+left_num+1,post_late+left_num,right_num);
}
int main()
{
int m=0,n;
scanf("%s",mid);
scanf("%s",late);
creat(0,0,strlen(mid));
return 0;
}
利用二叉树中序及后序遍历确定该二叉树的先序序列
最新推荐文章于 2022-01-07 11:00:00 发布