Home > Back-end >  In the binary tree sort order
In the binary tree sort order

Time:01-16

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:

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 draw program execution of the intermediate results step by step
  • Related