第5章 树与二叉树
5.3 二叉树的遍历和线索二叉树
综合应用题 第15题
![在这里插入图片描述](https://img-blog.csdnimg.cn/5e10e507b83f496b8384be08498d12ef.png)
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#define MaxSize 100
using namespace std;
typedef int ElemType;
void PreToPost(int pre[],int l1,int h1,int post[],int l2,int h2)
{
int half;
if(h1>=l1)
{
post[h2]=pre[l1];
half=(h1-l1)/2;
PreToPost(pre,l1+1,l1+half,post,l2,l2+half-1);
PreToPost(pre,l1+half+1,h1,post,l2+half,h2-1);
}
}
int main() {
int a[7]={4,2,1,3,5,6,7};
int b[7];
PreToPost(a,0,6,b,0,6);
cout<<"后序序列:";
for(int i=0;i<7;i++)
{
cout<<b[i]<<" ";
}
return 0;
}
![在这里插入图片描述](https://img-blog.csdnimg.cn/d462c0814b29437d848d96679ee10ee5.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAb25lIGRheV8xOTAzMDQ=,size_19,color_FFFFFF,t_70,g_se,x_16)