4518: 【入门】二叉排序树(2195)

内存限制:128 MB 时间限制:1.000 S
评测方式:文本比较 命题人:
提交:1 解决:1

题目描述

从键盘读入 lns="http://www.w3.org/1998/Math/MathML">n 个不相同的整数,以每个整数作为结点的值,来创建一棵二叉排序树,假设读入的第 lns="http://www.w3.org/1998/Math/MathML">1 个点是这棵树的根结点。

请求出这棵二叉排序树中序和后续遍历的结果?

输入

共两行,第一行为整数 lns="http://www.w3.org/1998/Math/MathML">n ;

第二行为 lns="http://www.w3.org/1998/Math/MathML">n 个不重复的整数 lns="http://www.w3.org/1998/Math/MathML">ai 。(lns="http://www.w3.org/1998/Math/MathML">0<n<105lns="http://www.w3.org/1998/Math/MathML">1ai105,本题中lns="http://www.w3.org/1998/Math/MathML">ai为随机生成的数值)

输出

共两行,第一行为中序遍历的结果,第二行为后序遍历的结果,同一行的输出用空格隔开。

样例输入 复制

8
23 45 12 6 7 89 13 47

样例输出 复制

6 7 12 13 23 45 47 89 
7 6 13 12 47 89 45 23