/*

Implement priority queue as ADT using multiple linked lists,one list for each priority for servicing patients in an hospital with priorities as
i) Serious (top priority)
ii) medium illness(medium priority)
iii) General (Least priority).

*/

#include<iostream>
#include<string.h>

using namespace std;

class queue
{
struct patient
{
char name[20];
patient *next;

patient()
{
name[0]='\0';
next=NULL;
}

void get()
{
cout<<"Enter the name of patient: ";
cin>>name;
}

void put()
{
cout<<"\nThe name of patient: ";
cout<<name;
}
};

patient *front,*rear,*temp;
 public:
queue()
{
front=rear=NULL;
}

int empty()
{
if(rear==NULL)
return 1;
return 0;
}
void insert();
void remove();
void display();
};


void queue::insert()
{
patient *npatient=new patient;
npatient->get();
if(empty())
front=rear=npatient;
else
{
rear->next=npatient;
rear=npatient;
}
}

void queue::remove()
{
patient *t=front;
if(empty())
cout<<"\nQUEUE is empty";
else
{
if(front==rear)
front=rear=NULL;
else
front=front->next;
t->put();
cout<<"\n GOt the treatment\n";
}
}

void qtype(int q)
{
if(q==1)
cout<<"\n1. Serious patient queue\n";
if(q==2)
cout<<"\n2. Medium Serious patient queue\n";
if(q==3)
cout<<"\n3. General Checkup patient queue\n";
}

void queue::display()
{
patient *temp=front;
while(temp!=NULL)
{
cout<<"\n"<<temp->name;
temp=temp->next;
}
}

int main()
{
queue q[3];
char ans,*n;
int priority,ch;
do
{
cout<<"\n1: Insert \n 2: Remove \n 3: Display\n4:EXIT";
cout<<"\n Enter u r choice : ";
cin>>ch;
switch(ch)
{
case 1:
cout<<"\nEnter the priority\n1.SERIOUS\n2.MEDIUM\n3.GENERAL";
cin>>priority;
q[priority].insert();
break;
case 2:
for(int i=0;i<3;i++)
{
qtype(i);
if(!q[i].empty())
{
q[i].remove();
break;
}
else
cout<<"EMPTY\n";
}
break;
case 3:
for(int i=0;i<3;i++)
{
qtype(i);
q[i].display();
}
break;
}
}while(ch!=4);
return 0;
}

//END OF PROGRAM