sdutacm-数据结构上机测试4.1:二叉树的遍历与应用1

数据结构上机测试4.1:二叉树的遍历与应用1

TimeLimit: 1000MS Memory Limit: 65536KB

SubmitStatistic

Problem Description

输入二叉树的先序遍历序列和中序遍历序列,输出该二叉树的后序遍历序列。

Input

第一行输入二叉树的先序遍历序列;
第二行输入二叉树的中序遍历序列。

Output

输出该二叉树的后序遍历序列。

Example Input

ABDCEF

BDAECF

Example Output

DBEFCA

Hint

Author

#include<string.h>
#include<stdio.h>
#include<stdlib.h>
#include<algorithm>
#include<queue>
#include<iostream>
using namespace std;
typedef struct node
{
   char data;
   struct node*l;
   struct node*r;
}tree;
void huifu(char *xian,char *zhong,int len)
{
  if(len==0)
  return ;
  tree *p = new tree;
  p->data = *xian;
  int i = 0;
  for(;i<len;i++)
  if(zhong[i]==*xian)
  {
     break;
  }
  huifu(xian+1,zhong,i);
  huifu(xian+i+1,zhong+i+1,len-i-1);
  cout<<p->data;
  return ;



}
int main()
{

   char xian[102],zhong[102];
   int i,len;
   scanf("%s%s",xian,zhong);
   len = strlen(xian);
   huifu(xian,zhong,len);
   cout<<endl;


}






/***************************************************
User name: jk160505徐红博
Result: Accepted
Take time: 0ms
Take Memory: 152KB
Submit time: 2017-02-07 15:04:24
****************************************************/

全部评论

相关推荐

12-14 11:43
黑龙江大学 Java
用微笑面对困难:确实比较烂,可以这么修改:加上大学的qs排名,然后大学简介要写一些,然后硕士大学加大加粗,科研经历第一句话都写上在复旦大学时,主要负责xxxx,简历左上角把学校logo写上,建议用复旦大学的简历模板
点赞 评论 收藏
分享
昨天 22:28
门头沟学院 Java
投递科大讯飞等公司6个岗位
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务