树形遍历的例子

问题描述 投票:0回答:1

我这里有这个二进制树,谁能确认一下我的后、前、后顺序遍历的顺序是否正确?如果不对,能举例说明一下过程吗?谢谢大家

                        20
                      /    \
                   15     28
                  /   \
                7     16
               /         \
              5         19

Left subtree, right subtree, then root node.
postOrder: 5 7 19 16 15 28 20

Root node visited first, then left and right subtree's.
preOrder:   20 15 7 5 16 19 28

Left subtree visited first, then the root, then right subtree.
inOrder:    5 7 15 16 19 20 28
binary-tree binary-search-tree
1个回答
0
投票

顺序前遍历:访问根节点,访问左侧节点,访问右侧子节点。你的说法是正确的.

顺序遍历:访问左节点,访问根节点,访问右节点。你的是正确的.

顺序后遍历:访问左节点,访问右节点,访问根节点。你的是正确的.

做得好!

© www.soinside.com 2019 - 2024. All rights reserved.