题目描述
A Binary Search Tree (BST) is recursively defined as a binary tree which
has the following properties:
The left subtree of a node contains only nodes with keys less thanthe node's key.
The right subtree of a node contains only nodes with keys greater
than orequaltothe node's key.
Both the left and right subtrees must also be binary search trees.
If we swap the left and right subtrees ofevery node, thenthe resulting
tree is called the Mirror Image of a BST.
Now given a sequence ofinteger keys, you are supposed totellifitisthe preorder traversal sequence of a BST orthe mirror image of a BST.
输入描述:
Each input filecontains one test case. For each case, thefirst line contains a positive integer N (<=1000). Then N integer keys are giveninthe next line. All the numbers in a line are separated by a space.
输出描述:
For each test case, first print in a line "YES"ifthe sequence isthe preorder traversal sequence of a BST orthe mirror image of a BST, or"NO"ifnot. Then ifthe answer is"YES", print inthe next line the postorder traversal sequence ofthat tree. All the numbers in a line must be separated by a space, and there must be no extra spaceattheendofthe line.
输入例子:
7865710811
输出例子:
YES
576811108
题目题目描述A Binary Search Tree (BST) is recursively defined as a binary tree whichhas the following properties:The left subtree of a node contains only nodes with keys less than the node's key. The rig