Struct Int Struct Struct Typedef Struct: "/nenter The Value: " "%D"
Struct Int Struct Struct Typedef Struct: "/nenter The Value: " "%D"
h>
#include<stdlib.h>
struct BST
{
int data;
struct BST *llink;
struct BST *rlink;
};
typedef struct BST * NODE;
NODE create()
{
NODE temp;
temp = (NODE) malloc(sizeof(struct BST));
printf("\nEnter The value: ");
scanf("%d", &temp->data);
temp->llink = NULL;
temp->rlink = NULL;
return temp;
}
void main()
{
int ch, key, val, i, n;
NODE root = NULL, newnode;
while (1)
{
printf("\n-------BST MENU-------");
printf("\n1. Create a BST ");
printf("\n2. Search ");
printf("\n3. BST Traversals: ");
printf("\n4. Exit");
printf("\nEnter your choice: ");
scanf("%d", &ch);
switch (ch)
{
case 1:
printf("\nEnter the number of elements: ");
scanf("%d", &n);
for (i = 1; i <= n; i++)
{
newnode = create();
if (root == NULL)
root = newnode;
else
insert(root, newnode);
}
break;
case 2:
if (root == NULL)
printf("\nTree Is Not Created ");
else
{
printf("\nThe Preorder display: ");
preorder(root);
printf("\nThe Inorder display: ");
inorder(root);
printf("\nThe Postorder display: ");
postorder(root);
}
break;
case 3:
search(root);
break;
case 4:
exit(0);
default:
printf("\nInvalid choice, please try again.");
}
}
}