How to search a number in a binary tree?

In, this program we find(search) out a number in a binary tree. when a number will present in a binary tree than they find out, otherwise the program will not give the output. here is program—-

=>Search a number in a binary tree.

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

int search(treenode*root,int x);

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

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

break;

case 1:
printf("enter the value to search");
scanf("%d",&data);
data= search(root,data);
if(data==0)
printf("Not found\n");
else
printf("Found");
break;

default:printf("not found");

}
}
return 0;
}

Leave a Reply