When to use the Order Tracking Strategy, In-Order and Post-Order
Before you can understand under what circumstances to use pre-order, order, and post-order for a binary tree, you need to understand exactly how each workaround strategy works. Use the following tree as an example.
Tree root 7 , leftmost node 0 , rightmost node 10 .

Bypass preview :
Summary: starts at the root ( 7 ), ends at the rightmost node ( 10 )
The sequence of passage: 7, 1, 0, 3, 2, 5, 4, 6, 9, 8, 10
Bypass in order :
Summary: starts at the leftmost node ( 0 ), ends at the rightmost node ( 10 )
The sequence of passage: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
Postprocessing :
Summary: begins with the leftmost node ( 0 ), ends with the root ( 7 )
The sequence of passage: 0, 2, 4, 6, 5, 3, 1, 8, 10, 9, 7
When to use pre-orders, orders or mail order?
The workaround strategy chosen by the programmer depends on the specific needs of the algorithm being developed. The goal is speed, so choose a strategy that brings you the nodes you need.
If you know that you need to research the roots before checking any leaves, you select a pre-order because you will meet all the roots in front of all the leaves.
If you know that you need to examine all the leaves in front of any nodes, you choose post-order , because you do not waste time checking the roots in the search for leaves.
If you know that the tree has an integral sequence in the nodes, and you want to smooth the tree back to the original sequence, then you should use the in-order traversal. The tree will be flattened just as it was created. Walking in order or in order may not cancel the tree back into the sequence that was used to create it.
Recursive algorithms for order, order and post-order (C ++):
struct Node{ int data; Node *left, *right; }; void preOrderPrint(Node *root) { print(root->name); //record root if (root->left != NULL) preOrderPrint(root->left); //traverse left if exists if (root->right != NULL) preOrderPrint(root->right);//traverse right if exists } void inOrderPrint(Node *root) { if (root.left != NULL) inOrderPrint(root->left); //traverse left if exists print(root->name); //record root if (root.right != NULL) inOrderPrint(root->right); //traverse right if exists } void postOrderPrint(Node *root) { if (root->left != NULL) postOrderPrint(root->left); //traverse left if exists if (root->right != NULL) postOrderPrint(root->right);//traverse right if exists print(root->name); //record root }