Dsaf
Dsaf
#include <stdio.h>
#include <stdlib.h>
int date;
char *activity;
};
scanf("%s", day->dayName);
scanf("%d", &day->date);
}
}
}
}
free(calendar[i].dayName);
free(calendar[i].activity);
}
int main() {
int size;
printf("Enter the number of days in the week: ");
scanf("%d", &size);
if (calendar == NULL) {
return 1;
}
read(calendar, size);
display(calendar, size);
freeMemory(calendar, size);
free(calendar);
return 0;
2
#include <stdio.h>
void stringmatch() {
while (str[c] != '\0') {
if (str[m] == pat[i]) {
i++;
m++;
if (pat[i] == '\0') {
flag = 1;
for (k = 0; rep[k] != '\0'; k++, j++) {
res[j] = rep[k];
}
i = 0;
c = m;
}
} else {
res[j] = str[c];
j++;
c++;
m = c;
i = 0;
}
}
res[j] = '\0';
}
int main() {
printf("Enter the main string: ");
fgets(str, sizeof(str), stdin);
str[strcspn(str, "\n")] = '\0';
if (flag == 1)
printf("\nThe string after pattern match and replace is:\n%s", res);
else
printf("\nPattern string not found");
return 0;
}
#include<stdio.h>
#include<stdlib.h>
#define MAX 3
top = -1;
void push(int item);
palindrome(); void
display();
void main()
{
int choice, item;
while (1)
{
printf("\n\n\n\n-----------Menu----------- : ");
printf("\n=>4.Display ");
printf("\n=>5.Exit");
switch (choice)
case 1:
printf("\nEnter an element to be pushed: ");
push(item);
break;
case 2:
item = pop();
if (item != -1)
break;
case 3:
palindrome();
break;
case 4:
display();
break;
case 5:
exit(1);
default:
break;
}
}
}
void push(int item)
if (top == MAX - 1)
{
printf("\n-----------Stack overflow-----------");
return;
}
top = top + 1;
s[top] = item;
int pop()
{ int item;
if (top == -1)
{
printf("\n-----------Stack underflow-----------");
return -1;
}
item = s[top];
top = top - 1;
return item;
void display()
{ int I;
if (top == -1)
printf("\n-----------Stack is empty-----------");
return;
}
printf("\nStack elements are:\n ");
}
void palindrome()
{ int flag = 1 i;
{
if (s[i] != s[top - i])
{
flag = 0;
break;
}
if (flag == 1)
else
{
printf("\nIt is not a palindrome number");
4
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#define SIZE 100
char stack[SIZE];
int top = -1;
void push(char c) {
stack[++top] = c;
}
char pop() {
return stack[top--];
}
int precedence(char op) {
switch (op) {
case '^': return 3;
case '*': case '/': case '%': return 2;
case '+': case '-': return 1;
default: return 0;
}
}
void infixToPostfix(char *exp) {
char postfix[SIZE];
int i = 0, j = 0;
infixToPostfix(exp);
return 0;
}
5a
#include <stdio.h>
#include <ctype.h>
#include <math.h>
int stack[SIZE];
int top = -1;
void push(int n) {
stack[++top] = n;
}
int pop() {
return stack[top--];
}
int main() {
char exp[SIZE];
return 0;
}
5b
#include <stdio.h>
{ if(n==0)
return;
source, destination);
void main()
int n;
6
#include<stdio.h>
#include<stdlib.h>
#define MAX 5
char circular_queue[MAX];
{
if (front == -1 && rear == -1)
return 1;
else
return 0;
int isFull()
{
return 1;
else
return 0;
{
printf("Circular Queue Overflow\n");
return;
}
else if (isEmpty())
{
front = rear = 0;
}
else
circular_queue[rear] = element;
}
void deleteElement()
if(isEmpty())
return;
}
else if (front == rear)
{
}
else
{
front = (front + 1) % MAX;
}}
void display()
Int i;
if (isEmpty())
{
}
printf("Circular Queue elements: ");
i = front;
do
{
printf("%c ", circular_queue[i]);
i = (i + 1) % MAX;
printf("\n");
}
int main()
{ int choice;
char element;
do
{
printf("\n\n---- Circular Queue Menu ----\n");
printf("1. Insert an Element\n");
Queue\n");printf("4. Exit\n");
scanf("%d", &choice);
switch(choice)
{
case 1:
insertElement(element);
break;
case 2:
deleteElement();
break;
case 3:
display();
break;
case 4:
printf("Exiting...\n");
break;
default:
}
}
while(choice != 4);
return 0;
7)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct Student {
int sem;
struct Student *next;
};
Node createNode() {
}
printf("Enter USN: ");
scanf("%s", newNode->usn);
scanf("%s", newNode->name);
scanf("%d", &newNode->sem);
scanf("%s", newNode->phone);
newNode->next = NULL;
return newNode;
}
Node insertFront(Node head) {
newNode->next = head;
return newNode;
}
return head;
}
Node deleteFront(Node head) {
if (!head) {
printf("List is empty!\n");
return NULL;
}
Node temp = head;
head = head->next;
free(temp);
return head;
}
if (!head) {
printf("List is empty!\n");
return NULL;
}
if (!head->next) {
free(head);
printf("Deleted from end.\n");
return NULL;
}
Node temp = head;
end.\n");
return head;
if (!head) {
printf("List is empty!\n");
return;
}
count = 0;
printf("Student List:\n");
while (temp) {
printf("USN: %s | Name: %s | Programme: %s |
Sem: %d | Phone: %s\n",
temp = temp->next;
count++;
}
int main() {
while (1) {
printf("\n--- MENU ---\n");
printf("6. Exit\n");
switch (choice) {
case 6: exit(0);
default: printf("Invalid choice!\n");
}
}
return 0;
8)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct Employee {
float sal;
Node createNode() {
Node newNode = (Node)malloc(sizeof(struct
Employee));
if (!newNode) {
scanf("%s", newNode->ssn);
scanf("%s", newNode->name);
scanf("%s", newNode->dept);
scanf("%s", newNode->designation);
printf("Enter Salary: ");
scanf("%f", &newNode->sal);
scanf("%s", newNode->phone);
}
Node insertEnd(Node head) {
newNode->prev = temp;
return head;
}
newNode->next = head;
head->prev = newNode;
return newNode;
}
Node deleteFront(Node head) {
if (!head) {
printf("List is empty!\n");
return NULL;
}
Node temp = head;
head = head->next;
printf("List is empty!\n");
return NULL;
}
if (!head->next) {
free(head);
}
Node temp = head;
temp->prev->next = NULL;
free(temp);
}
void display(Node head) {
if (!head) {
printf("List is empty!\n");
return;
}
Node temp = head; int
count = 0;
printf("Employee List:\n");
while (temp) {
count++;
}
}
int main() {
while (1) {
printf("6. Exit\n");
scanf("%d", &choice);
switch (choice) {
case 6: exit(0);
default: printf("Invalid choice!\n");
}
return 0;
9)
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
struct Term {
int coeff, x, y, z;
struct Term *next;
};
newTerm->x = x;
newTerm->y = y;
newTerm->z = z;
newTerm->next = newTerm;
return newTerm;
}
Node insertEnd(Node head, int coeff, int x, int y, int
z) {
Node newTerm = createTerm(coeff, x, y, z);
if (!head) return newTerm;
temp->next = newTerm;
newTerm->next = head;
return head;
}
void display(Node head) {
if (!head) {
printf("Polynomial is empty!\n");
return;
}
Node temp = head;
do {
printf("%+dx^%dy^%dz^%d ", temp->coeff,
temp->x, temp->y, temp->z);
temp = temp->next;
} while (temp != head);
printf("\n");
}
int evaluate(Node head, int x, int y, int z) {
int result = 0;
Node temp = head;
do {
result += temp->coeff * pow(x, temp->x) *
pow(y, temp->y) * pow(z, temp->z);
temp = temp->next;
do {
sum = insertEnd(sum, t1->coeff, t1->x, t1->y,
t1>z);
t1 = t1->next;
} while (t1 != p1);
Node t2 = p2;
do {
sum = insertEnd(sum, t2->coeff, t2->x, t2->y, t2-
>z);
t2 = t2->next;
return sum;
int main() {
Node poly1 = NULL, poly2 = NULL, polySum=NULL;
int n, coeff, x, y, z;
printf("POLY1: ");
display(poly1);
printf("POLY2: ");
display(poly2);
display(polySum);
return 0;
10)
#include <stdio.h>
#include <stdlib.h>
struct Node {
int data;
newNode->data = data;
newNode->left = newNode->right = NULL;
return newNode;
}
struct Node* insert(struct Node* root, int data) {
return root;
}
inorder(root->left);
inorder(root->right);
}
}
if (root) {
printf("%d ", root->data);
preorder(root->left);
preorder(root->right);
}
}
if (root) {
postorder(root->left);
postorder(root->right);
}
struct Node* search(struct Node* root, int key) {
int main() {
printf("6. Exit\n");
printf("Enter your choice: ");
scanf("%d", &choice);
switch (choice) {
case 1:
for (int i = 0; i <
sizeof(elements)/sizeof(elements[0]); i++)
break;
case 2:
printf("Inorder: ");
inorder(root);
printf("\n");
break;
case 3:
printf("Preorder: ");
preorder(root);
printf("\n");
break;
case 4:
printf("Postorder: ");
postorder(root);
printf("\n");
break;
case 5:
if (search(root, key))
printf("Element %d found in the BST.\n", key);
else
printf("Element %d not found in the BST.\n", key);
break;
case 6:
exit(0);
default:
printf("Invalid choice!\n");
}
return 0;
11)
#include <stdio.h>
#include <stdlib.h>
#define MAX 10
int i, j;
printf("Enter the number of cities: ");
scanf("%d", &n);
printf("Enter the adjacency matrix (0 for no edge,
1 for edge):\n");
scanf("%d", &adj[i][j]);
}
}
}
void DFS(int v) {
visited[v] = 1;
for (int i = 0; i < n; i++) {
DFS(i);
}
}
visited[start] = 1;
queue[rear++] = start;
int v = queue[front++];
for (int i = 0; i < n; i++) {
visited[i] = 1;
queue[rear++] = i;
int main() {
printf("4. Exit\n");
scanf("%d", &choice);
switch (choice) {
case 1:
createGraph();
break;
case 2:
DFS(start);
printf("\n");
break;
case 3:
BFS(start);
printf("\n");
break;
case 4:
exit(0);
default:
printf("Invalid choice!\n");
return 0;
}
---------------------------------------------------------------------
12)
#include<stdio.h>
#include<stdlib.h>
int key[20], n, m;
int count = 0;
void insert(int key)
{
index = key % m;
{
index = (index + 1) % m;
}
ht[index] = key;
count++;
}
void display()
{
int i;
if (count == 0)
{
void main()
{
int i;
printf("\nEnter the number of employee records (N): ");
ht[i] = -1;
{
if (count == m)
{
printf("\n-----Hash table is full. Cannot insert
the record %d key-----", i + 1);
break;
}
insert(key[i]);
display();
}