Dsa 1
Dsa 1
printf("\nThe contents of SLL: \n"); case 3: start = insertend(); while (cur != NULL) { case 2:
cur = start; break; if (cur -> data == key){ if (root == NULL)
while (cur != NULL) case 4: printf("\nKey element is present in BST "); printf("\nTree Is Not Created ");
{ start = deleteend(); return; else{
printf("\n|%d| |USN:%s| |Name:%s| |Branch:%s| |Sem:%d| |Ph:%ld|", num, cur -> break; } printf("\nThe Preorder display: ");
usn , cur -> name, cur -> branch, cur -> sem, cur -> phone); case 5: if (key < cur -> data) preorder(root);
cur = cur -> link; stackdemo(); cur = cur -> lchild; printf("\nThe Inorder display: ");
num++; break; else inorder(root);
} case 6: cur = cur -> rchild; printf("\nThe Postorder display: ");
printf("\n No of student nodes is %d \n", count); exit(0); } postorder(root);
} default: printf("\nKey element is not found in the BST "); }
void stackdemo() { printf("\nPlease enter the valid choice");} } break;
int ch; } void inorder(NODE root){ case 3:
while (1){ } if (root != NULL){ search(root);
printf("\n--------Stack Demo using SLL ------------ \n"); inorder(root -> lchild); break;
printf("\n1:Push operation \n2: Pop operation \n3: Display \n4:Exit \n"); TEN: printf("%d ", root -> data); case 4:
printf("\nEnter your choice for stack demo:"); inorder(root -> rchild); exit(0);
scanf("%d", &ch); #include<stdio.h> } } }
switch (ch){ #include<stdlib.h> void preorder(NODE root){ }}
case 1: struct BST { if (root != NULL) {
start = insertfront(); int data; printf("%d ", root -> data);
break; struct BST * lchild; preorder(root -> lchild); ELEVEN:
case 2: struct BST * rchild; preorder(root -> rchild);
start = deletefront(); }; }} #include<stdio.h>
break; typedef struct BST * NODE; void postorder(NODE root){ #include<stdlib.h>
case 3: NODE create(){ if (root != NULL){ int a[50][50], n, visited[50];
display(); NODE temp; postorder(root -> lchild);
temp = (NODE) malloc(sizeof(struct BST));
int q[20], front = -1, rear = -1;
break; postorder(root -> rchild); int s[20], top = -1, count = 0;
default: printf("\nEnter The value: "); printf("%d ", root -> data);
scanf("%d", & temp -> data); void bfs(int v) {
return; }}
} temp -> lchild = NULL; void main() { int i, cur;
} temp -> rchild = NULL; int ch, key, val, i, n; visited[v] = 1;
return; return temp; NODE root = NULL, newnode; while (1) q[++rear] = v;
}int main(){ } { while (front != rear) {
int ch, i, n; while (1) void insert(NODE root, NODE newnode){ printf("\n-------BST MENU ----------- "); cur = q[++front];
{ if (newnode -> data < root -> data) { printf("\n1.Create a BST ");
if (root -> lchild == NULL) for (i = 1; i <= n; i++) {
printf("\n--------Menu ------------- "); printf("\n2.Search ");
root -> lchild = newnode; if ((a[cur][i] == 1) && (visited[i] == 0)) {
printf("\nEnter your choice for SLL operation\n"); printf("\n3.BST Traversals: ");
printf("\n1:Create SLL of Student Nodes"); else printf("\n4.Exit"); q[++rear] = i; visited[i] = 1; printf("%d ", i);
printf("\n2:DisplayStatus"); insert(root -> lchild, newnode); printf("\nEnter your choice: "); }}}
printf("\n3:InsertAtEnd"); } scanf("%d", & ch); }
printf("\n4:DeleteAtEnd"); if (newnode -> data > root -> data){ switch (ch) void dfs(int v){
printf("\n5:Stack Demo using SLL(Insertion and Deletion at Front)"); if (root -> rchild == NULL) { int i; visited[v] = 1;
printf("\n6:Exit\n"); root -> rchild = newnode; case 1:
else s[++top] = v;
printf("\nEnter your choice:"); printf("\nEnter the number of elements: ");
insert(root -> rchild, newnode); for (i = 1; i <= n; i++){
scanf("%d", & ch); scanf("%d", & n);
switch (ch){ }} for (i = 1; i <= n; i++) { if (a[v][i] == 1 && visited[i] == 0)
case 1: void search(NODE root) { newnode = create(); {
printf("\nEnter the no of students: "); int key; if (root == NULL) printf("%d ", i);
scanf("%d", & n); NODE cur; root = newnode; dfs(i);
for (i = 1; i <= n; i++) if (root == NULL) { else }}
start = insertfront(); printf("\nBST is empty."); insert(root, newnode);
return; }
break; }
case 2: } break;
display(); printf("\nEnter Element to be searched: ");
break; scanf("%d", & key);
cur = root;