Procedure Inorder (Bt)
The above Procedure traverses the binary tree using Inorder traversal method, the pointer ‘Bt’ points to the root node. Node structure is same as discussed earlier. The Procedure traverses the binary tree in a recursive manner.
Step 1 Is empty ?
if (BtEmpty (Bt)) them
message : “Empty tree”
return
Step 2 Traverse the left sub-tree
if (Lchild (Bt) NULL) then
call to Inorder (Lchild (Bt))
Step 3 Process the root node
if (Bt NULL) then
display ; data (Bt)
Step 4 Traverse the right sub-tree
if (Rchild (Bt) NULL) then
call to Inorder (Rchild (Bt)
Step 5 Return at the point of call
return
code is given below:
void Inorder_Traversal (node * Bt)
{
if (Bt ! = NULL)
{
Inorder_Traversal (Bt Lchild);
prinft (“%d”, Bt item)
Inorder_Traversal (Bt Rchild);
}
}
No comments:
Post a Comment