10 binary
10 binary
h>
# include <stdlib.h>
# include <conio.h>
int flag=0;
int data;
}node;
void main()
root = NULL;
clrscr();
do {
printf("\n1.Create");
printf("\n2.Search");
printf("\n3.Recursive Traversals");
printf("\n4.Exit");
scanf("%d", &choice);
switch (choice)
case 1:
do {
new_node = get_node();
scanf("%d", &new_node->data);
root = new_node;
else
insert(root, new_node);
scanf("%d",&ans);
} while (ans);
break;
case 2:
scanf("%d", &key);
if(flag==1)
else
flag=0;
break;
case 3:
if (root == NULL)
else
inorder(root);
preorder(root);
postorder(root);
break;
getch();
node *get_node()
node *temp;
temp->lchild = NULL;
temp->rchild = NULL;
return temp;
if(root->lchild == NULL)
root->lchild = new_node;
else
insert(root->lchild, new_node);
if (root->rchild == NULL)
root->rchild = new_node;
else
insert(root->rchild, new_node);
/*This function is for searching the node from binary Search Tree*/
if (temp->data == key)
flag=1;
return temp;
}
*parent = temp;
temp = temp->lchild;
else
temp = temp->rchild;
return NULL;
/*
*/
if (temp != NULL)
inorder(temp->lchild);
printf("%d\t", temp->data);
inorder(temp->rchild);
/*
if (temp != NULL)
printf("%d\t", temp->data);
preorder(temp->lchild);
preorder(temp->rchild);
}
/*This function displays the tree in postorder fashion */ void postorder(node *temp)
if (temp != NULL)
postorder(temp->lchild);
postorder(temp->rchild);
printf("%d\t", temp->data);