DSA Assignnment Final
DSA Assignnment Final
BELAGAVI - 590018
Assignment -1
Submitted in partial fulfilment for the requirement of the award of degree
of
BACHELOR OF ENGINEERING
IN
Computer science and engineering
BY
Build a hospital system where patients are queued based on their arrival and
processed in FIFO order. Use queues for regular patients and priority queues
for emergency cases. Each patient’s details can be stored in a linked list.
INTRODUCTION:
In data structures, a queue is a linear data structure that operates in a First-In-First-
Out (FIFO) order, meaning the first element added to the queue is the first one to be
removed. This feature makes queues ideal for scenarios where tasks or entities need
to be processed in the order they arrive, such as in waiting lines, scheduling systems,
or, in this case, a hospital management system.
In a hospital environment, a queue can effectively manage the flow of patients by
organizing them based on their arrival time or the urgency of their needs. This
model allows for efficient and fair processing of patients, ensuring that those who
arrive first are served first, except in emergency cases, which are handled by a
separate priority queue for faster treatment.
Types of Queues
There are various types of queues, each with specific characteristics and
applications. Common types include:
1. Linear Queue: This is the most basic form of a queue where elements are
added at the rear (end) and removed from the front. Once an element is
removed, the memory is not reused, which can lead to inefficiency as the
queue fills up from the rear end.
2. Circular Queue: Unlike a simple queue, a circular queue connects the end of
the queue back to the front, creating a circular structure. This allows more
efficient memory use, as freed spaces at the front can be reused.
Page | 2 2024-25
Data structure and applications BCS304
Linked list
A linked list is a linear data structure in which elements, called nodes, are stored in a
sequence but not in contiguous memory locations. Each node in a linked list
contains two main parts:
1. Data - The actual information or value.
2. Link - A reference to the next node in the sequence.
Types of Linked Lists
1. Singly Linked List:
In a singly linked list, each node contains a single link that points to the next
node in the sequence. The list starts with a head node (the first node) and ends
at the last node, which has a NULL link.
Page | 3 2024-25
Data structure and applications BCS304
DESIGN:
Problem Analysis
The primary objective of the program is to design a patient management system for
a hospital that organizes patients into separate queues based on urgency: emergency
cases and regular cases. The system is required to:
- Regular patients follow a simple first-in, first-out (FIFO) order, which can be
managed with a standard queue.
Page | 4 2024-25
Data structure and applications BCS304
We defined a Patient structure to store details for each patient, including an ID,
name, age, emergency status, and a pointer to the next patient.
Two separate queue structures (Queue struct pointers) manage patients: one for
regular patients and another for emergency cases.
Initialization:
Two queues, emergencyQueue and regularQueue, are initialized. The front and rear
pointers for each queue are set to NULL initially, indicating that the queues are
empty.
Patient Enqueueing:
Patients are added to the queues based on user input.
For regular patients, the system simply appends the new patient to the end of the
regular queue.
For emergency patients, the program prompts the user to select a specific emergency
condition (e.g., heart attack, major accident) and assigns a corresponding priority
level.
The emergency queue inserts each patient based on their emergency priority,
ensuring patients with higher urgency are positioned closer to the front of the queue.
This design allows for efficient patient management, prioritizing emergency cases
while ensuring a structured treatment process that respects both the urgency and
order of arrival for each patient.
Page | 5 2024-25
Data structure and applications BCS304
IMPLIMENTATION :
Page | 6 2024-25
Data structure and applications BCS304
Page | 7 2024-25
Data structure and applications BCS304
Page | 8 2024-25
Data structure and applications BCS304
COMPLETE CODE:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
} else {
// Queue is not empty, add patient to the rear
queue->rear->next = patient;
queue->rear = patient;
}
}
if (queue->rear == NULL) {
queue->rear = patient;
}
} else {
// Traverse the list until we find the correct position
PATIENT current = queue->front;
while (current->next != NULL) {
// Break if we find a patient with a lower priority
if (current->next->emergencyType > patient->emergencyType) {
break;
}
current = current->next;
}
Page | 10 2024-25
Data structure and applications BCS304
if (emergencyStatus) {
// Ask for specific emergency type
printf("Select Emergency Type:\n");
printf("1 - Heart Attack\n2 - Pregnant Woman\n3 - Major Accident (Heavy
Bleeding)\n4 - Accident with Minor Danger\n");
printf("Enter choice (1-4): ");
scanf("%d", &emergencyType);
int main() {
// Create and initialize queues
QUEUE emergencyQueue = (QUEUE)malloc(sizeof(struct Queue));
QUEUE regularQueue = (QUEUE)malloc(sizeof(struct Queue));
initQueue(emergencyQueue);
initQueue(regularQueue);
int numPatients, i;
printf("Enter the number of patients to add: ");
scanf("%d", &numPatients);
Page | 12 2024-25
Data structure and applications BCS304
return 0;
}
OUTPUT:
Page | 13 2024-25
Data structure and applications BCS304
Page | 14 2024-25
Data structure and applications BCS304
APPLICATIONS:
REFERANCES:
References related to queuing and priority systems:
Websites
1. Khan Academy - Probability and Statistics
Khan Academy
This site offers lessons on probability and statistics, which are foundational
for understanding queuing theory.
2. Coursera - Operations Management: Analysis and Improvement
Methods
Coursera
This course includes sections on queuing systems in operations management.
Page | 16 2024-25