## Tree Traversal

In our previous sections we have constructed binary trees. Now we want to visit each of the nodes in a tree and print the values one by one. The process of visiting node of a tree is known as Tree-I Iteration or Tree enumeration or Tree Traversal. There are several common orders in which the nodes can be visited, and each has practical implications. There are broadly three types of Tree Traversal logics available:
• Pre-Order
• In-Order
• Post-Order

## Pre-Order

Visit Root then Visit Left child and then Right child.

``` 1  void pre_order (struct node* node) {
2    if (node == NULL) {
3      return;
4    } else {
5      printf ("%d", node->value);
6      pre_order (node->left);
7      pre_order (node->right);
8    }
9  }
10  ```

## In-Order

Visit Left child, then Visit Root, and Visit Right child.

``` 1  void in_order (struct node* node) {
2    if (node == NULL) {
3      return;
4    } else {
5      in_order (node->left);
6      printf ("%d", node->value);
7      in_order (node->right);
8    }
9  }
10  ```

## Post-Order

Visit Left Child, Visit Right child, then Visit Root.

``` 1  void post_order (struct node* node) {
2    if (node == NULL) {
3      return;
4    } else {
5      post_order (node->left);
6      post_order (node->right);
7      printf ("%d", node->value);
8    }
9  }
10  ```

## Depth-first Search Order

Depth-first order visit root and iterate immediately till the depth of the child tree without visiting same level nodes. Recursion is used to do this iteration. There is no need to remember same level nodes as we call recursively for each child starting from root. This iteration takes a child of root visits entire sub tree till leaf node and further takes another child and completes entire depth and in this way completes entire iteration. Pre-Order is one of the special cases of depth first search order.