This is a sequence of binary tree traversal, when performing the first judgment after received the value on the left, which is the root, hold values determine whether the right after, so called again, if the left there is no value on the right values are not stopped? Then the value of is how to traverse the out? Don't think this algorithm, guide request bosses,
CodePudding user response:
This is a normal DFS traversal, if two child nodes of the current node explain the current node is a leaf node is empty, this route can be ended, otherwise continue down the recursive search, until the leaf node of the current line
CodePudding user response:
Do you have any misunderstanding on recursion? If the left and continue the recursive traversal left. (this is the first if) If does not meet the above, or if, after the traversal, above is traverse the current node, called the assignment statements in the middle of the two sentences if the If the right, then continue to recursive traversal right subtree (that is, the second if) So, to your question, about all have no, only perform intermediate one (about cycle for the first time, if all have no, only perform intermediate that sentence, that is 2; If the left will recursive traversal 1 first, for recursive Lai said 1, around which all have no, it is only carried out in the middle of the statement, in the middle of the statement is 1) You draw a diagram to the execution of a program step by step the intermediate results was clear to draw