Binary search Tree Comparison

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.