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

PROGRAMMING:Two level node statistics of binary search tree

Luz5年前 (2021-05-10)题库492
**A binary search tree * * is either an empty tree or a binary tree with the following properties: if its left subtree is not empty, then the values of all nodes on the left subtree are less than or equal to the values of its root nodes; If its right subtree is not empty, then the values of all nodes on the right subtree are greater than the values of its root node; Its left and right subtrees are also binary search trees.
Insert a series of numbers into an initially empty binary search tree in a given order. Your task is to count the number of nodes in the bottom two layers of the result tree.
Input format: input a positive integer $$n $$($$Le 1000 $$) in the first line, which is the number of inserted numbers. The second line gives the integers in the $$n $$[- 10001000] $. Numbers are separated by spaces.
Output format: output the total number of nodes in the bottom two layers in a row.
Input example: 9
25 30 42 16 20 20 35 -5 28
Output example: 6







answer:If there is no answer, please comment