BST Program 10
BST Program 10
printf("\nBST is empty."); return; } int ch, key, val, i, n; int a[50][50], n, visited[50];
printf("\nEnter Element to be searched: "); NODE root = NULL, newnode; int q[20], front = -1,rear = -1;
scanf("%d", &key); while(1){ printf("\n~~~~BST MENU~~~~"); int s[20], top = -1, count=0;
while (cur != NULL) { if (cur->data == key){ printf("\n3.BST Traversals: ");printf("\n4.Exit"); int i, cur;
printf("\nKey element is present in BST"); return; } printf("\nEnter your choice: ");scanf("%d", &ch); visited[v] = 1;
else cur = cur->rchild; } case 1: printf("\nEnter the number of elements: "); while(front!=rear) {
printf("\nKey element is not found in the BST"); } scanf("%d", &n); for(i=1;i<=n;i++) { cur = q[++front];
cur = cur->lchild; else case 2: if (root == NULL) visited[i] = 1; printf("%d ", i); {{{{
printf("\nKey element is not found in the BST"); } printf("\nThe Preorder display : "); visited[v]=1;
void preorder(NODE root) { printf("\nThe Postorder display : "); printf("%d ", i);
postorder(root->rchild); } for(j=1;j<=n;j++)
visited[i]=0;
printf("\nEnter the starting vertex: "); #include <stdio.h> HARSH TABLE 12 printf("Collision avoided successfully using LINEAR PROBING\n");
printf("\n==>1. BFS: Print all nodes reachable from a given starting node"); #include <conio.h> printf("\n Hash table is full");
printf("\n==>2. DFS: Print all nodes reachable from a given starting node"); #define MAX 20 display(a);
case 1: printf("\nNodes reachable from starting vertex %d are: ", start); void display (int[]); if(a[i] == -1) { a[i] = num;
printf("\nThe vertex that is not reachable is %d" ,i); } break; display(a); a[i] = num;
case 2: printf("\nNodes reachable from starting vertex %d are:\n",start); printf(" collision handling by linear probing : \n"); flag=1;
case 3: exit(0); printf("\n Enter 4 digit employee key\n"); scanf("%4d", &num); i++; } } }
void linear_prob(int a[MAX], int key, int num) { printf("\n %d %d ", i, a[i]);
else { if(a[i]!=-1) {
i=0; break;
if (a[i]!=-1) }}
count++; i++; }