Preface:
Binary search tree is a two-fork sorting tree, Supi root small, right sub-tree than the root, so its contribution to the way and common achievements of the way slightly different, each time to compare with the root node and determine the location, and then traverse the binary tree node to determine whether two trees are exactly equal.
At the same time, in the Ox-Guest Web page compiler running results are not the same, but in the local debugging is no problem, and the test, also did not find any logic error, the question is doubtful ~ ~ ~
Title Descriptiondetermine if two sequences are the same one or two-fork search tree sequence
Input Description:
Starting with a number n, (1<=n<=20) indicates that there are n needs to be judged, n= 0 when the input ends.
The next line is a sequence, the sequence length is less than 10, contains (0~9) number, no repetition number, according to this sequence can construct a binary search tree.
The next n rows have n sequences, and each sequence format is the same as the first sequence, so please determine whether the two sequences can form the same binary search tree.
Output Description:
Output Yes if the sequence is the same, otherwise the output no
Input Example:
2
567432
543267
576342
0
Output Example:
YES
NO
The code is as follows:
Binary search Tree Comparison