That s not a binary tree
与2个单元相关的是: 因此,一 tree树是一种树,任何树子要么是一leaf(没有孩子),要么是“有2个孩子”。 基本上,所有节点都有0至2名儿童。
Your picture isn t a binary tree: Node D has 3 children. Node B has only 1.
But you can pre-order traversal just fine
序前的 trav树与纯双 trees树毫不相干。 它是一种适用于树木的算法。 不需要树木是双向树。
To pre-order this one:
- Start at the root.
- Emit the value of the currently selected node.
- Go through the children it has in left-to-right order. For each child, recursively apply this algorithm at step 2.
各位都必须这样做。 此处适用:
- Start at the root.
- Emit its value: We have
"A"
- Loop through its direct children - apply this algorithm to B and C.
对B的再保险将最终印成<代码>“BDHIJ”,对C的再保险将印成“CEG。 最终结果为ABDHIJCEG>
。
There s no such thing as skipping the middle node unless you are reading some tutorial or explanation that says first iterate the left side, then, iterate the right side . Those terms ( left side and right side ) presume a binary tree. There is no mention of the middle node because the explanation assumes a binary tree; binary trees don t have middle nodes.
一些穿透器,如在座的,不适用于非白化树。 这是因为他们访问了左边,然后是 no子,然后是右手。 这对非白化树没有意义。 但是,顺序前并没有这样做,因此可以轻而易举地扩大到N-ary 树木。