给了二叉树的先序遍历给成后续遍历。。
解题: 分而治之。。
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
#include<iostream> #include<string.h> #include<algorithm> #include<stdio.h> using namespace std; const int maxn=100000; int number[maxn]; void solve(int s,int e) { if(s==e) {cout<<number[s]<<endl;return ;} int i=s; for( i=s+1;i<=e;i++) if(number[i]>number[s]) break; if(s+1<=i-1)solve(s+1,i-1); if(i<=e)solve(i,e); cout<<number[s]<<endl; } int main() { int i=-1; while(scanf("%d",&number[++i])!=EOF); solve(0,i-1); return 0; }