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

PROGRAMMING:Building binary search tree and finding parent node

Luz5年前 (2021-05-10)题库410
The binary search tree is established according to the input order, and a node is searched, and its parent node is output.
###Input format:
There are three lines of input:
The first line is n value, which means there are n nodes;
The second line has n integers, representing the data values of N nodes;
The third line is x, which indicates the parent node of the node with the value of X to be searched.
###Output format:
Output the value of the parent node of the node whose value is X.
If the node with value x does not exist, output: it does not exist
If the node with value x is the root node, the output is: it doesn't have parent
###Input example:
```in
two
twenty
thirty
twenty
```
###Output example:
```out
It doesn't have parent.
```
###Input example:
```in
two
twenty
thirty
thirty
```
###Output example:
```out
twenty
```







answer:If there is no answer, please comment