Dsa 10
Dsa 10
ASSIGNMENT NAME:= implement priority queue as ADT using singly link list for servising patient is
an
#include<iostream>
#include<string.h>
struct node
int data,prior;
char pnm[10],name[10];
}*front,*rear;
class Queue
public:
int isempty();
void display();
void p_delete();
};
int Queue::isempty()
if((rear=front)==NULL)
return 1;
return 0;
{
struct node *temp;
temp=new node;
strcpy(temp->pnm,name);
temp->prior=prior;
temp->next=NULL;
return temp;
int i;
temp=createnode(prior,name);
if(isempty())
front=rear=temp;
temp->next=front;
front=temp;
else
rear=front;
rear=rear->next;
temp->next=rear->next;
rear->next=temp;
}
}
void Queue::display()
for(temp=front;temp!=NULL;temp=temp->next)
if(temp->prior==1)
cout<<temp->prior<<"\t \t serious\t\t"<<temp->pnm<<endl;
if(temp->prior==2)
if(temp->prior==3)
void Queue::p_delete()
temp=front;
front=front->next;
temp->next=NULL;
delete temp;
display();
int main()
int priority,i,ch,n;
int ans,patient_no;
char name[10];
Queue q;
do
cout<<"\n 2.display";
cout<<"\n 3.delete";
cin>>ch;
switch(ch)
case 1:
cout<<"\n 1.serious";
cout<<"\n 2.medium";
cout<<"\n 3.normal";
cin>>n;
for(i=0;i<n;i++)
cin>>priority;
cin>>name;
q.pq_insert(priority,name);
break;
case 2:
q.display();
break;
case 3:
q.p_delete();
break;
case 4:
cin>>ch;
break;
cin>>ans;
}while(ans==1);
return 0;
}