Showing posts with label implementation of inorder traversal in c. Show all posts
Showing posts with label implementation of inorder traversal in c. Show all posts

Thursday, April 5, 2012

Inorder Traversal of Binary Search Tree

 
To traverse a non-empty tree in inorder the following steps are followed recursively.
  • Visit the Root
  • Traverse the left subtree
  • Traverse the right subtree
The inorder traversal of the tree shown below is as follows.




Algorithm



The algorithm for inorder traversal is as follows.


Struct node
{
struct node * lc;
int data;
struct node * rc;
};


void inorder(struct node * root);
{
if(root != NULL)
{
inorder(root-> lc);
printf("%d\t",root->data);
inorder(root->rc);
}
}


So the function calls itself recursively and carries on the traversal.