[Daily OJ - 94. In-order traversal of binary trees]

1. Topic: 94. In-order traversal of binary tree

Insert image description here

2.Solution

2.1. Algorithm explanation

1. First of all, if you open up space for the array every time each node is traversed, the efficiency is too low, so we optimize by directly counting the number of nodes in the binary tree that need to be traversed. As the size of the space opened up by the array, this is extremely effective in saving the tedious operation of opening up space sequentially every time it is traversed.
2. Next, implement the function interface of in-order traversal. It should be noted that the order of in-order traversal is: left subtree->root->right subtree, in-order traversal When the array stores binary tree node data, the subscript i needs to be received by a pointer, otherwise the i value subscript of the array will be accumulated recursively on the left and right and lead to out-of-bounds.
3. The last step is to implement the function interface that returns an array storing binary tree data after in-order traversal.

2.2. Code implementation

Insert image description here

2.3.Submission through display

Insert image description here

Guess you like

Origin blog.csdn.net/qq_73900397/article/details/134803412