-->
当前位置:首页 > 题库

PROGRAMMING:Complete binary search tree

Luz5年前 (2021-05-10)题库368
To insert a series of given numbers into an initially empty binary search tree (defined as the key value of the left subtree is large and the key value of the right subtree is small), you need to judge whether the final tree is a complete binary tree, and give the sequence traversal results.
###Input format:
Enter the first line to give a positive integer 'n' no more than 20; The second line gives' n 'distinct positive integers separated by spaces.
###Output format:
Insert the 'n' positive integers into a binary search tree which is initially empty. In the first line, the sequence traversal results of the result tree are output, the numbers are separated by a space, and there must be no extra space at the beginning and end of the line. The second line outputs' yes' if the tree is a complete binary tree; Otherwise, output ` no '.
###Input sample 1:
```in
nine
38 45 42 24 58 30 67 12 51
```
###Output sample 1:
```out
38 45 24 58 42 30 12 67 51
YES
```
###Input example 2:
```
eight
38 24 12 45 58 67 42 51
```
###Output example 2:
```
38 45 24 58 42 12 67 51
NO
```






answer:If there is no answer, please comment