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

PROGRAMMING:Binary tree creation and query

Luz5年前 (2021-05-10)题库432
To create a binary tree, the node stores integer data. The rule is: the first value is the root of the binary tree, the value less than the parent node is placed in the left child node, and the value greater than the parent node is placed in the right child node.
On the basis of creating a good binary tree, query, through the input value to query, find out its parent node, child node, brother node.
Output binary tree preorder, middle order, after order traversal results.
###Input format:
The input value is integer type, and it can be input in multiple lines.
The first line: the number of nodes of the binary tree.
Second line: values of nodes, separated by commas.
The third line: the node value to query.
###Output format:
The first line outputs the parent node of the node to be queried.
The second line outputs the child node of the node to be queried.
The third line outputs the sibling node.
The fourth is the result of binary tree preorder traversal.
The fifth is the result of traversal in binary tree.
The sixth is the result of binary tree traversal.
###Input example:
Here is a set of inputs. For example:
```in
eight
5,2,9,11,4,23,10,16
twenty-three
```
###Output example:
The corresponding output is given here. For example:
```out
23's parents are 11
23 left children are 16 no right children
23's brother is 10
Preorder results 5,2,4,9,11,10,23,16
Middle order results 2,4,5,9,10,11,16,23
The following results are 4,2,10,16,23,11,9,5
```
###Input sample 2:
Here is a set of inputs. For example:
```in
one
seven
seven
```
###Output sample 2:
The corresponding output is given here. For example:
```out
No parents
7 no children
No brothers
Antecedent result 7
Middle order result 7
Next result 7
```






answer:If there is no answer, please comment