#include<stdio.h>
#include<conio.h>
typedef struct prque
{
char p_name[20];
int prn;
struct prque *next;
}prque;
prque * insert(prque *);
prque * delet(prque *);
void display(prque *);
int main()
{
int i,ch,n,prn1;
char p_name1[20];
prque *front;
clrscr();
front=NULL;
do
{
printf("\n1)Patient Entry");
printf("\n2)Delete");
printf("\n3)display Patiant List.");
printf("\n4)Exit");
printf("\nEnter your choice:");
scanf("%d",&ch);
switch(ch)
{
case 1:
front=insert(front);
break;
case 2: printf("\nPatient Name Deleted:%s\n",front->p_name);
front=delet(front);
break;
case 3: display(front);
break;
case 4:exit(0);
}
}while(ch!=4);
getch();
return 0;
}
prque *insert(prque *front)
{
char p_name[20];
int prn;
prque *temp,*current,*prev;
temp=(prque*)malloc(sizeof(prque));
printf("\nEnter patient name:");
scanf("%s",temp->p_name);
printf("\nEnter Status:\n1)General Check up\t2)Non Serious\t3)Serious.\t");
scanf("%d",&prn);
temp->prn=prn;
temp->next=NULL;
if(front==NULL)
{
front=temp;
}
else
{
if(prn>front->prn)//Insert at front
{
temp->next=front;
front=temp;
}
else if(prn<=front->prn) //insert at middle
{
current=front;
while(current->prn>=prn && current!=NULL)
{
prev=current;
current=current->next;
}
temp->next=prev->next;
prev->next=temp;
}
}
return(front);
}
prque * delet(prque *front)
{
prque *temp;
if(front==NULL)
{
printf("\nQueue is Underflow.");
return(front);
}
else
{
temp=front;
front=front->next;
free(temp);
}
return(front);
}
void display(prque *front)
{
prque *p;
p=front;
printf("\n--------------------------------------------------");
printf("\n\tPatient Name\t\tPriority\n");
printf("--------------------------------------------------");
while(p!=NULL)
{
printf("\n\t%s",p->p_name);
if(p->prn==3)
printf("\t\t\tSerious");
else if(p->prn==2)
printf("\t\t\tNon serious");
else if(p->prn==1)
printf("\t\t\tGenaral Checkup");
p=p->next;
}
}
/*
Output:
1)Patient Entry
2)Delete
3)display Patiant List.
4)Exit
Enter your choice:1
Enter patient name:Afridi
Enter Status:
1)General Check up 2)Non Serious 3)Serious. 3
1)Patient Entry
2)Delete
3)display Patiant List.
4)Exit
Enter your choice:1
Enter patient name:Ponting
Enter Status:
1)General Check up 2)Non Serious 3)Serious. 2
1)Patient Entry
2)Delete
3)display Patiant List.
4)Exit
Enter your choice:1
Enter patient name:Sangakara
Enter Status:
1)General Check up 2)Non Serious 3)Serious. 3
1)Patient Entry
2)Delete
3)display Patiant List.
4)Exit
Enter your choice:
1
Enter patient name:Clerke
Enter Status:
1)General Check up 2)Non Serious 3)Serious. 1
1)Patient Entry
2)Delete
3)display Patiant List.
4)Exit
Enter your choice:2
Patient Name Deleted:Afridi
1)Patient Entry
2)Delete
3)display Patiant List.
4)Exit
Enter your choice:1
Enter patient name:Vittori
Enter Status:
1)General Check up 2)Non Serious 3)Serious. 2
1)Patient Entry
2)Delete
3)display Patiant List.
4)Exit
Enter your choice:1
Enter patient name:Dilshan
Enter Status:
1)General Check up 2)Non Serious 3)Serious. 3
1)Patient Entry
2)Delete
3)display Patiant List.
4)Exit
Enter your choice:1
Enter patient name:Malinga
Enter Status:
1)General Check up 2)Non Serious 3)Serious. 1
1)Patient Entry
2)Delete
3)display Patiant List.
4)Exit
Enter your choice:2
Patient Name Deleted:Sangakara
1)Patient Entry
2)Delete
3)display Patiant List.
4)Exit
Enter your choice:3
--------------------------------------------------
Patient Name Priority
--------------------------------------------------
Dilshan Serious
Ponting Non serious
Vittori Non serious
Clerke Genaral Checkup
Malinga Genaral Checkup
1)Patient Entry
2)Delete
3)display Patiant List.
4)Exit
Enter your choice:2
Patient Name Deleted:Dilshan
1)Patient Entry
2)Delete
3)display Patiant List.
4)Exit
Enter your choice:2
Patient Name Deleted:Ponting
1)Patient Entry
2)Delete
3)display Patiant List.
4)Exit
Enter your choice:2
Patient Name Deleted:Vittori
1)Patient Entry
2)Delete
3)display Patiant List.
4)Exit
Enter your choice:2
Patient Name Deleted:Clerke
1)Patient Entry
2)Delete
3)display Patiant List.
4)Exit
Enter your choice:2
Patient Name Deleted:Malinga
1)Patient Entry
2)Delete
3)display Patiant List.
4)Exit
Enter your choice:2
Patient Name Deleted:(null)
Queue is Underflow.
1)Patient Entry
2)Delete
3)display Patiant List.
4)Exit
Enter your choice:4
*/
Written by: Fabianski Benjamin
yes
the priority queue is which depends on the data stored.in which their priority is maintained by checking the forth coming values stored in the queue
A priority queue is a queue in which each element is inserted or deleted on the basis of their priority. A higher priority element is added first before any lower priority element. If in case priority of two element is same then they are added to the queue on FCFS basis (first come first serve). Mainly there are two kinds of priority queue: 1) Static priority queue 2) Dynamic priority queue
Separated queue for every possible priority value.
A priority queue is a collection of elements that each element has been assigned a priority and such that order in which elements are deleted and processed comes from the following riles: 1) An element of higher priority is processed before any element of lower priority. 2) Two element with the same priority are processed according to the order in which they were added to the queue.
yes
A circular queue is similar to the normal queue with the difference that queue is circular queue ; that is pointer rear can point to beginning of the queue when it reaches at the end of the queue. A priority queue is a queue in which each element is inserted or deleted on the basis of their priority. A higher priority element is added first before any lower priority element. If in case priority of two element is same then they are added to the queue on FCFS basis (first come first serve).
Ascending priority queue is a collection of items which can be inserted aurbitarly and which can be removed smallest item. Descending priority queue is similar to ascending priority queue but it allows the deletion of the largest item.
the priority queue is which depends on the data stored.in which their priority is maintained by checking the forth coming values stored in the queue
A priority queue is a queue in which each element is inserted or deleted on the basis of their priority. A higher priority element is added first before any lower priority element. If in case priority of two element is same then they are added to the queue on FCFS basis (first come first serve). Mainly there are two kinds of priority queue: 1) Static priority queue 2) Dynamic priority queue
Separated queue for every possible priority value.
Two possible solutions: 1. Separated queue for every possible priority value. 2. One shared queue for every elements, sorted by priority.
A priority queue is a collection of elements that each element has been assigned a priority and such that order in which elements are deleted and processed comes from the following riles: 1) An element of higher priority is processed before any element of lower priority. 2) Two element with the same priority are processed according to the order in which they were added to the queue.
The queue is a linear data structure where operations of insertion and deletion are performed at separate ends also known as front and rear. Queue is a FIFO structure that is first in first out. A circular queue is similar to the normal queue with the difference that queue is circular queue ; that is pointer rear can point to beginning of the queue when it reaches at the end of the queue. Advantage of this type of queue is that empty location let due to deletion of elements using front pointer can again be filled using rear pointer. A priority queue is a queue in which each element is inserted or deleted on the basis of their priority. A higher priority element is added first before any lower priority element. If in case priority of two element is same then they are added to the queue on FCFS basis (first come first serve). Mainly there are two kinds of priority queue: 1) Static priority queue 2) Dynamic priority queue A double ended queue (or deque ) is a queue where insertion and deletion can be performed at both end that is front pointer can be used for insertion (apart from its usual operation i.e. deletion) and rear pointer can be used for deletion (apart from its usual operation i.e. insertion)
Queue is a data structure which is based on FIFO that is first in first out. Following are the types of queue: Linear queue Circular queue Priority queue Double ended queue ( or deque )
yes,cursor implementation possible in priority queue.
No. The program counter must be stored in a dedicated register. The stack is in working memory and you cannot operate on working memory; all values must be moved into a register in order to operate upon them. It makes no sense to move a program counter in and out of memory unless performing a context switch and you can't use a stack for context switching; a priority queue must be used for this. Keep in mind that the address of the top of the stack has to be moved in and out of its register during a context switch. It doesn't make sense to load the stack register from a priority queue before you can determine where the program counter value is. It's easier to keep all state information in the same place in the priority queue where it belongs.