Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

1

D – section, Batch:2018; I - Year - II Semester


Data Structure and Algorithm Design Assignment
B.Md.Rafiq Oulia -
2018HW86492

Assignment WIPRO WASE/WIMS 2018 Batch MM: 10

Problem Statement
Dr. Saxena runs a clinic for senior citizens which see a large number of patients coming in
everyday. In order to avoid inconvenience to the aged patients, the rule is that the oldest
patient is examined first by the doctor. As the patients keep coming and registering, they are
added to a priority list from which patient’s names are called out for consultation.

Since it is very difficult managing all this with pen and paper, Dr. Saxena thought of having
appointment software for this.

The software should be capable of:

1. Taking the patient’s details as input and creates a patient ID in the format < xxxxyy>
where xxxx is the unique patient number and yy is the patient’s age.

2. Insert the patients in the priority list based on the age of the patient. Maintain a priority
queue implemented using linked lists.

3. Display the next patient name in line to meet the doctor and remove this patient from the
priority list.

//Patient Record

Struct Patient{
Int age;
Char *name;
Char *patient_id;
}
Functions

2018HW86492 - BITS - ID
1. Char *registerPatient(char *name, int age): This function registerPatient accepts the
name and age of the patient entering the hospital and returns patient_Id of the patient.
Patient_Id is formed by concatenating a unique number generated by this function with age of
patient.
Function should start generating unique numbers with 1001 and then increment it by one every time
a new patient is registered.
2. addPatient(Patient P): This function assigns the patient P a place in the queue depending on
their age. This function should be called every time a new patient is added and should keep
the queue updated as per the age condition.
3. nextPatient(): This function prints the patient_Id and name of the patient that is next in line
to meet the doctor and remove that patient from the list.

Perform an analysis of functions 2 and 3 and give the running time in terms of input size n.

Source code:

# include<stdio.h>
# include<malloc.h>
#include<string.h>

typedef struct node


{
int age;
char name[50];
char info[50];
struct node *link;
int patientId;
}NODE;
NODE *front = NULL;

/*ID generation*/
int registerId()
{
static int count = 1000;
count++;
return count;
}

/*Begin of insert*/
void registerPatient(char name[20],int age)
{
NODE *tmp,*q;

tmp = (NODE *)malloc(sizeof(NODE));


strcpy(tmp->info, name);
//tmp->info = name;
tmp->age = age;
/*Queue is empty or item to be added has priority more than first item*/
if( front == NULL || age > front->age )
{
tmp->link = front;
front = tmp;

2018HW86492 - BITS - ID
}
else
{
q = front;
while( q->link != NULL && q->link->age >= age )
q=q->link;
tmp->link = q->link;
q->link = tmp;
}

}
/*End of insert*/

/*Begin of del*/
void nextPatient()
{
NODE *tmp;
if(front == NULL)
printf("Queue Underflow\n");
else
{
tmp = front;
printf("Next Patient is %s\n",tmp->info);
front = front->link;
free(tmp);
}
}
/*End of del*/

/*Begin of display*/
void display()
{
NODE *ptr;
ptr = front;
if(front == NULL)
printf("Queue is empty\n");
else
{
printf("Queue is :\n");
printf("age Item\n");
while(ptr != NULL)
{
printf("%5d %5s\n",ptr->age,ptr->info);
ptr = ptr->link;
}
}
}
/*End of display*/

/*Begin of main*/
int main()
{
int choice,age,patientId=0;
char name[20];
do

2018HW86492 - BITS - ID
{
printf("1.Insert\n");
printf("2.Next Patient\n");
printf("3.Display\n");
printf("4.Quit\n");
printf("Enter your choice : ");
scanf("%d", &choice);
switch(choice)
{
case 1:
printf("Enter the patient's name : ");
//scanf("%s",&name);
//fflush(stdin);
fgets ( name, sizeof name, stdin);
gets(name);
printf("Enter the patient's age : ");
scanf("%d",&age);
registerPatient(name,age);
printf("patient ID :%d%d", registerId(),age);
printf("\nPatient Name : %s",name);
printf("\nPatient Age : %d\n",age);
break;
case 2:
nextPatient();
break;
case 3:
display();
break;
case 4:
break;
default :
printf("Wrong choice\n");
}
}while(choice!=4);

return 0;
}
/*End of main*/

Output screen shot:

Options and also queue empty:

Without inserting data if we choose display option, output will be as shown below.

2018HW86492 - BITS - ID
Inserting patient record:

When we inserting data of patients by choosing insert option it will take the input of the patient as
shown below.

Display records:

After inserting data if we choose display option it will show the data of the patient as shown in
below.

2018HW86492 - BITS - ID
Display next record and also queue underflow:

2018HW86492 - BITS - ID
After inserting data if we choose next patient option it will show data of next patient as per in queue.
Once queue got over it shows output as queue underflow as shown below.

2018HW86492 - BITS - ID

You might also like