0% found this document useful (0 votes)
4 views1 page

Dsa 1

Uploaded by

Prarthana TL
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views1 page

Dsa 1

Uploaded by

Prarthana TL
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

SIX: SEVEN: printf("\nThe Student node with usn:%s is deleted", temp -> usn);

#include<stdio.h> void display() count--;


#include<stdlib.h> { int i; #include<stdio.h > free(temp);
#define MAX 5 if (isEmpty()) #include<stdlib .h> return start;
char circular_queue[MAX]; { struct node }
int front = -1, rear = -1; printf("Circular Queue is empty\n"); { NODE insertend()
int isEmpty() return; char usn[25], name[25], branch[25]; {
{ } int sem; NODE cur, temp;
if (front == -1 && rear == -1) printf("Circular Queue elements: "); long int phone; temp = create();
return 1; i = front; struct node *link; if
else do }; (start == NULL)
return 0; { typedef struct node * NODE;NODE start = NULL; {
} printf("%c ", circular_queue[i]); int count = 0; return temp;
int isFull() i = (i + 1) % MAX; NODE create() }
{ } { cur = start; while (cur -> link != NULL)
if ((rear + 1) % MAX == front) while (i != (rear + 1) % MAX); NODE snode; {
return 1; printf("\n"); snode = (NODE)malloc(sizeof(struct node)); cur = cur -> link;
else } if(snode == NULL) }
return 0; int main() { cur -> link = temp;
} { printf("\nMemory is not available"); return start;
void insertElement(char element) int choice; exit(1); }
{ char element; } NODE deleteend()
if (isFull()) do printf("\nEnter the usn,Name,Branch, sem,PhoneNo of the student:"); {
{ { scanf("%s %s %s %d %ld", snode -> usn, snode -> name, snode -> branch, & snode NODE cur, prev;
printf("Circular Queue Overflow\n"); printf("\n\n---- Circular Queue Menu -------- \n"); -> sem, & snode -> phone); if (start == NULL)
return; printf("1. Insert an Element\n"); snode -> link = NULL; {
} printf("2. Delete an Element\n"); count++; printf("\nLinked List is empty");
else if (isEmpty()) printf("3. Display Circular Queue\n"); return snode; return NULL;
{ printf("4. Exit\n"); } }
front = rear = 0; printf("Enter your choice: "); NODE insertfront(){ if (start -> link == NULL)
} scanf("%d", &choice);switch(choice) NODE temp; {
else { temp = create(); printf("\nThe student node with the usn:%s is deleted", start -> usn);
{ case 1: if (start == NULL) free(start);
rear = (rear + 1) % MAX; printf("Enter element to be inserted: "); { count--;
} scanf(" %c", &element); return temp; return NULL;
circular_queue[rear] = element; insertElement(element); } }
} break; temp -> link = start; prev = NULL;
void deleteElement() case 2: return temp; cur = start;
{ deleteElement(); } while (cur -> link != NULL)
if (isEmpty()) break; NODE deletefront() {
{ case 3: { prev = cur;
printf("Circular Queue Underflow\n"); display(); NODE temp; cur = cur -> link;
return; break; if (start == NULL) }
} case 4: { printf("\nThe student node with the usn:%s is deleted", cur -> usn);
else if (front == rear) printf("Exiting. ... \n"); printf("\nLinked list is empty"); free(cur);
{ break; return NULL; prev -> link = NULL;
front = rear = -1; } }if (start -> link == NULL) count--;
} } { return start;
else while(choice != 4);return 0; printf("\nThe Student node with usn:%s is deleted ", start -> usn); }
{ } count--; void display()
front = (front + 1) % MAX; free(start); {
} return NULL; NODE cur;
} } int num = 1;if (start == NULL)
temp = start; {printf("\nNo Contents to display in SLL \n");
start = start -> link; return;
}

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;

int main(){ TWELVE:


int ch, start, i, j;
printf("\nEnter the number of vertices in graph:"); #include<stdio.h>
scanf("%d", & n); #include<stdlib.h>
printf("\nEnter the adjacency matrix:\n"); int key[20], n, m;
for (i = 1; i <= n; i++) int * ht, index;
{ int count = 0;
for (j = 1; j <= n; j++) void insert(int key){
scanf("%d", & a[i][j]); index = key % m;
} while (ht[index] != -1){
for (i = 1; i <= n; i++) index = (index + 1) % m;
visited[i] = 0; }
printf("\nEnter the starting vertex: "); ht[index] = key;
scanf("%d", & start); count++;
printf("\n==>1. BFS: Print all nodes reachable from a given starting node"); }
printf("\n==>2. DFS: Print all nodes reachable from a given starting node"); void display(){
printf("\n==>3:Exit"); int i;
printf("\nEnter your choice: "); if (count == 0) {
scanf("%d", & ch); printf("\nHash Table is empty");
switch (ch) return;
{ }
case 1: printf("\nHash Table contents are:\n ");
printf("\nNodes reachable from starting vertex %d are: ", start); for (i = 0; i < m; i++)
bfs(start); printf("\n T[%d] --> %d ", i, ht[i]);
for (i = 1; i <= n; i++) }
{ void main()
if (visited[i] == 0) {
printf("\nThe vertex that is not reachable is %d", i); int i;
} printf("\nEnter the number of employee records (N): ");
break; scanf("%d", & n);
case 2: printf("\nEnter the two digit memory locations (m) for hash table: ");
printf("\nNodes reachable from starting vertex %d are:\n", start); dfs(start); scanf("%d", & m);
break; ht = (int * ) malloc(m * sizeof(int));
case 3: for (i = 0; i < m; i++)
exit(0); ht[i] = -1;
default: printf("\nEnter the four digit key values (K) for N Employee Records:\n "); for (i = 0; i < n; i++)
printf("\nPlease enter valid choice:"); scanf("%d", & key[i]);
} for (i = 0; i < n; i++) {
} if (count == m) {
printf("\n-----Hash table is full. Cannot insert the record %d key --- ", i + 1);
break;
}
insert(key[i]);
}
display();
}

You might also like