How to print the value of nodes in binary tree in the form of pre order?

When we know how to print the value of nodes in a binary tree than with the help of in this program, we also know how to print the value of nodes in the form of pre-order.here is program——-

1==>Pre order In, this program we print the value of nodes in the form of pre-order.pre-order workes on the individual pattern like(N, L, R),  In this pattern N-node, L-left and R- right.

 

typedef struct tree
{
int data;
struct tree *lft;
struct tree *rt;
}treenode;

void preOrder(treenode* root);

int main()
{
int option,data;
treenode *root=NULL;

while(1)
{
menu();
printf(“enter the choice”);
scanf(“%d”,&option);
switch(option)
{
case 0:
return 0;

case 1:
printf(“\nPre order\n”);
preOrder(root);
break;

default:printf(“not found”);

}
}
return 0;
}

void preOrder(treenode* root)
{
if(root==NULL)
return;
printf(“%d,”,root->data);
preOrder(root->lft);
preOrder(root->rt);
}

Leave a Reply