简化版由前序遍历和中序遍历返回后序遍历

#include<iostream>
#include<cstring>
#include<string>
#include<stdio.h>
using namespace std;


void print(int n,char *x,char *y)
{
    if(n<=0)
    return;

    int lon= strchr (y,x[0])-y;
    print(lon,x+1,y);
    print(n-lon-1,x+lon+1,y+lon+1);

    cout << x[0] ;
}

int main()
{
    char x[30],y[30];
    while(cin >> x >> y)
    {
        int n=strlen(x);
        print(n,x,y);
        cout << endl; 
    }
}

 

posted @ 2021-05-03 21:06  wind_bell  阅读(53)  评论(0)    收藏  举报