The Above figure describes the order of traversals among themselves.
Below is the code for recursive traversals
struct node
{
int info;
struct node *llink;
struct node *rlink;
};
typedef struct node *NODE;
void preorder(NODE root)
{
if(root==NULL)
return;
printf("%d",root->info);
preorder(root->llink);
preorder(root->rlink);
}
void inorder(NODE root)
{
if(root==NULL)
return;
inorder(root->llink);
printf("%d",root->info);
inorder(root->rlink);
}
void postorder(NODE root)
{
if(root==NULL)
return;
postorder(root->llink);
postorder(root->rlink);
printf("%d",root->info);
}
No comments:
Post a Comment