As long as the computer is engaged in, the binary tree traversal in the data structure is not unfamiliar, but if the opportunity used is not much, then it will gradually fade away. Reviewing the past is the best way to learn. Now, review the knowledge in this regard.
First of all, I want to change the names of these traversals (pre-radical traversal, mid-radical traversal, post-radical traversal); the former, middle and post-radical traversal are originally relative to the root node, and a word less will lead to many unnecessary misunderstandings.
1. Pre-root order traversal: first traverse the root node, then traverse the left subtree, and finally traverse the right subtree.
ABDHECFG
2. Medium root order traversal: first traverse the left subtree, then traverse the root node, and finally traverse the right subtree.
HDBEAFCG
3. Later root order traversal: first traverse the left subtree, then traverse the right subtree, and finally traverse the root node.
HDEBFGCA
The process of constructing a binary tree is as follows:
1. Establish the root node according to the first element of the pre-radical sequence.
2. Find the element in the mid-root sequence and determine the mid-root sequence of the left and right subtrees of the root node.
3. Determine the pre-radical sequence of left and right subtrees in the pre-radical sequence;
4. The left subtree is constructed from the front and middle root sequence of the left subtree.
5. The right subtree is constructed from the front and middle root sequence of the right subtree.
The process of constructing a binary tree is as follows:
1. Establish the root node according to the last element of the post-radical sequence.
2. Find the element in the mid-root sequence and determine the mid-root sequence of the left and right subtrees of the root node.
3. Determine the post-root sequence of left and right subtrees in the post-root sequence;
4. The left subtree is constructed from the posterior and middle root sequence of the left subtree.
5. The right subtree is constructed from the posterior and middle root sequence of the right subtree.
Print the post-root code according to the pre-and middle-root order: