簡體   English   中英

樹遍歷示例

[英]Tree Traversal examples

我這里有這個二叉樹,誰能確認我對 post、pre 和 in order 遍歷的順序是否正確? 如果沒有,你能舉例說明這個過程嗎? 謝謝

                        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

前序遍歷:訪問根節點,訪問左節點,訪問右子節點。 你的是正確的

中序遍歷:訪問左節點,訪問根節點,訪問右節點。 你的是正確的

后序遍歷:訪問左節點,訪問右節點,訪問根。 你的是正確的

干得好!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM