Traversing binary search tree is very important as most of its objectives are accomplished by traversing in various ways. Most popular Binary Search Tree traversals are

- Inorder Traversal of Binary Search Tree
- Preorder Traversal of Binary Search Tree
- Postorder Traversal of Binary Search Tree

**Pre-order traversals**: the root node is visited, then the child nodes (left to right).**In-order traversals:**only makes sense in binary trees – the left node will be visited, then the root node, and then the right node.**Post-order traversals**: the child nodes will be visited before the root node (left to right).

void inorder ( struct tnode *p){

if( p != NULL){

inorder(p->left);

printf("%d\t",p->data);

inorder(p->right);

}

}

` `

`void preorder ( struct tnode *p){`

if( p != NULL){

printf("%d\t",p->data);

preorder(p->left);

preorder(p->right);

}

}

` `

`void postorder ( struct tnode *p){`

if( p != NULL){

postorder(p->left);

postorder(p->right);

printf("%d\t",p->data);

}

}

Advertisements