Three traversal methods of binary tree

. Preface
Binary tree: refers to a tree with only two child nodes and a total of three nodes: the root node, the left child node, and the right child node.
Insert picture description here

According to the traversal order of the three nodes, it is divided into three types: preorder, middle order and postorder traversal.

Note: The root node modified by the previous location word (I think I can remember this by knowing this)

Preorder:
Root node -> Left child node -> Right child node: A->B->C

Middle order:
left child node -> root node -> right child node: B->A->C

Post sequence:
left child node -> right child node -> root node: B->C->A

When the child node encountered is not a leaf node, the above steps are nested to read.

The more important of the three traversals is the in-order traversal, because many sorts (such as heap sort) are used. (I will find time to write about the realization of the three traversals)

Guess you like

Origin blog.csdn.net/qq_43530773/article/details/114487144