-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogram6
More file actions
101 lines (87 loc) · 2.31 KB
/
program6
File metadata and controls
101 lines (87 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include <stdio.h>
#include <stdlib.h>
#define MAX 5
struct Queue {
int front, rear;
int calls[MAX];
};
void initializeQueue(struct Queue *q) {
q->front = q->rear = -1;
}
int isFull(struct Queue *q) {
return (q->front == (q->rear + 1) % MAX);
}
int isEmpty(struct Queue *q) {
return (q->front == -1);
}
void enqueue(struct Queue *q, int call) {
if (isFull(q)) {
printf("Overflow: Queue is full. Cannot add more calls.\n");
} else {
if (isEmpty(q)) {
q->front = q->rear = 0;
} else {
q->rear = (q->rear + 1) % MAX;
}
q->calls[q->rear] = call;
printf("Call added successfully.\n");
}
}
void dequeue(struct Queue *q) {
if (isEmpty(q)) {
printf("Underflow: Queue is empty. No calls to remove.\n");
} else {
printf("Call %d removed.\n", q->calls[q->front]);
if (q->front == q->rear) {
initializeQueue(q);
} else {
q->front = (q->front + 1) % MAX;
}
}
}
void displayQueue(struct Queue *q) {
if (isEmpty(q)) {
printf("Queue is empty.\n");
} else {
printf("Current status of calls: ");
int i = q->front;
do {
printf("%d ", q->calls[i]);
i = (i + 1) % MAX;
} while (i != (q->rear + 1) % MAX);
printf("\n");
}
}
int main() {
struct Queue callQueue;
initializeQueue(&callQueue);
int choice, call;
do {
printf("\n----- Call Center Simulation -----\n");
printf("1. Add a call\n");
printf("2. Delete a call\n");
printf("3. Display current status of calls\n");
printf("4. Exit\n");
printf("Enter your choice: ");
scanf("%d", &choice);
switch (choice) {
case 1:
printf("Enter the call number: ");
scanf("%d", &call);
enqueue(&callQueue, call);
break;
case 2:
dequeue(&callQueue);
break;
case 3:
displayQueue(&callQueue);
break;
case 4:
printf("Exiting the program.\n");
break;
default:
printf("Invalid choice. Please try again.\n");
}
} while (choice != 4);
return 0;
}