-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathds_khush_12.c
More file actions
99 lines (89 loc) · 2.11 KB
/
ds_khush_12.c
File metadata and controls
99 lines (89 loc) · 2.11 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
#include <stdio.h>
#include <string.h>
#define MAX 5 // maximum number of patients
char queue[MAX][50]; // array of strings to store patient names
int front = -1, rear = -1;
// Function to add patient
void enqueue(char name[])
{
if (rear == MAX - 1)
{
printf("\nQueue is full! No more patients can be added.\n");
return;
}
if (front == -1)
front = 0;
rear++;
strcpy(queue[rear], name);
printf("Patient '%s' added to the queue.\n", name);
}
// Function to remove patient
void dequeue()
{
if (front == -1 || front > rear)
{
printf("\nNo patients in the queue.\n");
return;
}
printf("Patient '%s' is now seeing the doctor.\n", queue[front]);
front++;
}
// Function to show next patient
void showNext()
{
if (front == -1 || front > rear)
{
printf("\nNo patients waiting.\n");
return;
}
printf("Next patient to see the doctor: %s\n", queue[front]);
}
// Function to display all patients
void displayQueue()
{
if (front == -1 || front > rear)
{
printf("\nNo patients waiting.\n");
return;
}
printf("\nPatients in queue:\n");
for (int i = front; i <= rear; i++)
{
printf("%d. %s\n", i - front + 1, queue[i]);
}
}
int main()
{
int choice;
char name[50];
printf("🏥 Hospital Patient Management System 🏥\n");
while (1)
{
printf("\n1. Add Patient\n2. Serve Patient\n3. Show Next Patient\n4. Display All Patients\n5. Exit\n");
printf("Enter your choice: ");
scanf("%d", &choice);
getchar(); // to clear newline
switch (choice)
{
case 1:
printf("Enter patient name: ");
gets(name);
enqueue(name);
break;
case 2:
dequeue();
break;
case 3:
showNext();
break;
case 4:
displayQueue();
break;
case 5:
printf("Exiting... Stay healthy!\n");
return 0;
default:
printf("Invalid choice! Try again.\n");
}
}
}