answersLogoWhite

0

#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

User Avatar

Wiki User

12y ago

What else can I help you with?

Related Questions

Array implementation of priority queue example program in c plus plus?

yes


What is the difference between a priority queue and a circular queue?

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).


What are the difference between ascending priority queue and descending queue?

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.


Array implementation of priority queue?

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


What is the time complexity for inserting an element into a priority queue?

The time complexity for inserting an element into a priority queue is O(log n), where n is the number of elements in the priority queue.


What is the time complexity of inserting an element into a priority queue?

The time complexity of inserting an element into a priority queue is O(log n), where n is the number of elements in the priority queue.


What is the time complexity of popping an element from a priority queue?

The time complexity of popping an element from a priority queue is O(log n), where n is the number of elements in the priority queue.


What is the process for inserting a keyword into a priority queue?

To insert a keyword into a priority queue, you first assign a priority value to the keyword based on its importance. Then, you add the keyword to the queue according to its priority, ensuring that higher priority keywords are placed at the front of the queue. This process helps in efficiently managing and accessing the keywords based on their priority levels.


What are the different types of queues?

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


Minimum number of queues needed to implement the priority queue?

Separated queue for every possible priority value.


How many minimum no of queues Rae needed to implement priority queue?

Two possible solutions: 1. Separated queue for every possible priority value. 2. One shared queue for every elements, sorted by priority.


What are the advantages of using a decrease key operation in a priority queue to efficiently manage the priority of elements?

Using a decrease key operation in a priority queue allows for efficiently changing the priority of elements. This can lead to faster updates and better performance in managing the order of elements in the queue.