DSA Assignment (Abhishek 1AY23CS004)
DSA Assignment (Abhishek 1AY23CS004)
1
ABHISHEK KUMAR
1AY23CS004
Question 1:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char name[50];
int age;
int registrationNumber;
} Participant;
typedef struct {
Participant* front;
Participant* rear;
} Queue;
void initializeQueue(Queue* q) {
strcpy(newParticipant->name, name);
newParticipant->age = age;
newParticipant->registrationNumber = regNum;
newParticipant->next = NULL;
return newParticipant;
if (q->rear == NULL) {
return;
q->rear->next = newParticipant;
q->rear = newParticipant;
void dequeue(Queue* q) {
if (q->front == NULL) {
return;
q->front = q->front->next;
if (q->front == NULL) {
q->rear = NULL;
printf("Processed participant: %s, Age: %d, Registration Number: %d\n", temp->name, temp->age,
temp->registrationNumber);
free(temp);
void peek(Queue* q) {
if (q->front == NULL) {
printf("Next participant in line: %s, Age: %d, Registration Number: %d\n", q->front->name, q-
>front->age, q->front->registrationNumber);
void displayQueue(Queue* q) {
if (q->front == NULL) {
return;
printf("Name: %s, Age: %d, Registration Number: %d\n", temp->name, temp->age, temp-
>registrationNumber);
temp = temp->next;
void freeQueue(Queue* q) {
free(temp);
temp = next;
int main() {
Queue q;
initializeQueue(&q);
int choice;
char name[50];
printf("Abhishek kumar\n");
printf("USN: 1AY23CS004\n\n");
do {
printf("5. Exit\n");
scanf("%d", &choice);
switch (choice) {
case 1:
scanf("%s", name);
scanf("%d", &age);
scanf("%d", ®Num);
break;
case 2:
dequeue(&q);
break;
case 3:
peek(&q);
break;
case 4:
displayQueue(&q);
break;
case 5:
freeQueue(&q);
printf("Exiting...\n");
break;
default:
return 0;
OUTPUT:
Abhishek kumar
USN: 1AY23CS004
5. Exit
Enter your choice: 1
5. Exit
5. Exit
Next participant in line: Aditya kumar , Age: 20, Registration Number: 013
5. Exit
5. Exit
Exiting...
Question 2:
#include <stdio.h>
#include <string.h>
int main() {
char sentence[1000];
char word[100];
printf("Abhishek kumar\n");
printf("USN: 1AY23CS004\n");
readInput(sentence, word);
deleteWord(sentence, word);
displayResult(sentence);
return 0;
}
scanf("%s", word);
char* pos;
if (strlen(sentence) > 0) {
} else {
printf("No deletions were made. The sentence does not contain the specified word.\n");
OUTPUT:
Abhishek kumar
USN: 1AY23CS004