蓝桥杯-算法训练 求先序排列

问题描述

给出一棵二叉树的中序与后序排列。求出它的先序排列。(约定树结点用不同的大写字母表示,长度<=8)。

输入格式

两行,每行一个字符串,分别表示中序和后序排列

输出格式

一个字符串,表示所求先序排列

样例输入

BADC
BDCA

样例输出

ABCD

锦囊1

后序的最后一个字母为根结点。

锦囊2

先将后序的最后一个字母取出,作为根结点,以中序遍历将左右子树分开,然后分别处理。

参考代码

此处为隐藏的内容!
发表评论并刷新,才能查看

 

俊霖

发表评论

您必须

目前评论:6   其中:访客  6   博主  0


    Warning: A non-numeric value encountered in /www/wwwroot/jurieo.com/wp-content/themes/begin2.0/inc/function/comment-template.php on line 20
  1. watchfree watchfree 4

    Warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in /www/wwwroot/jurieo.com/wp-content/themes/begin2.0/inc/function/default.php on line 566
  2. Deepsilent 1

    Warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in /www/wwwroot/jurieo.com/wp-content/themes/begin2.0/inc/function/default.php on line 566
  3. ymx200181 5

    Warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in /www/wwwroot/jurieo.com/wp-content/themes/begin2.0/inc/function/default.php on line 566
  4. liu123 0

    Warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in /www/wwwroot/jurieo.com/wp-content/themes/begin2.0/inc/function/default.php on line 566
  5. qq1125160107 1

    Warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in /www/wwwroot/jurieo.com/wp-content/themes/begin2.0/inc/function/default.php on line 566
  6. wwwaaannnggg 0

    Warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in /www/wwwroot/jurieo.com/wp-content/themes/begin2.0/inc/function/default.php on line 566