SlideShare a Scribd company logo
Priority Queue as a Heap Array
Emergency Room Patient Admittance
Objectives
• Build a priority queue as a heap stored in an array
• Dequeue the next priority item and maintaining the heap
For this assignment, you will be implementing a class of your own: a priority queue,
which is a variation on the standard queue. The standard queue processes element
in the first-in, first-out ("FIFO") manner typical of ordinary waiting lines. Queues can
be handy, but a FIFO strategy isn't always what's needed. A hospital emergency
room, for example, needs to schedule patients according to priority. A patient with a
more critical problem will pre-empt others even if they have been waiting longer.
This is a priority queue, where elements are prioritized relative to each other and
when asked to dequeue one, it is the highest priority element in the queue that is
removed.
The priority queue will store a collection of structs that keep track of the patient
name and an integer for the priority. Smaller integers are considered higher priority
than larger ones and are dequeued ahead of larger values.
The header file is provided with a struct to maintain the patient information and a
class to maintain the priority queue. In this example, assume all priority numbers
are unique (in a real ER program, the numbers may be from 1 to 10 plus the date/time
stamp to determine who came in first when multiple have the same priority).
Specifications
• Use the provided header file – do not change in any way!
• Test your program with the provided driver program – without changing the
driver program your output should match what is provided below.
Expected Output
From the provided driver program, your output should appear as follows:
Adding 22 Lila
===
Patients Waiting
[22] Lila
===
Processing 22 Lila
===
NEXT! - Lila
===
Patients Waiting
No one waiting!
===
Adding 3 Liz
===
Patients Waiting
[3] Liz
===
Adding 19 Xylo
===
Patients Waiting
[3] Liz
[19] Xylo
===
Adding 20 Zedder
===
Patients Waiting
[3] Liz
[19] Xylo
[20] Zedder
===
Adding 15 Ratner
===
Patients Waiting
[3] Liz
[15] Ratner
[20] Zedder
[19] Xylo
===
Adding 7 Tattle
===
Patients Waiting
[3] Liz
[7] Tattle
[20] Zedder
[19] Xylo
[15] Ratner
===
Adding 6 Sassy
===
Patients Waiting
[3] Liz
[7] Tattle
[6] Sassy
[19] Xylo
[15] Ratner
[20] Zedder
===
Adding 2 Elle
===
Patients Waiting
[2] Elle
[7] Tattle
[3] Liz
[19] Xylo
[15] Ratner
[20] Zedder
[6] Sassy
===
Adding 1 Alph
===
Patients Waiting
[1] Alph
[2] Elle
[3] Liz
[7] Tattle
[15] Ratner
[20] Zedder
[6] Sassy
[19] Xylo
===
Adding 5 Ophra
===
Patients Waiting
[1] Alph
[2] Elle
[3] Liz
[5] Ophra
[15] Ratner
[20] Zedder
[6] Sassy
[19] Xylo
[7] Tattle
===
Adding 4 Mommy
===
Patients Waiting
[1] Alph
[2] Elle
[3] Liz
[5] Ophra
[4] Mommy
[20] Zedder
[6] Sassy
[19] Xylo
[7] Tattle
[15] Ratner
===
Processing 1 Alph
===
NEXT! - Alph
9 patients currently waiting.
Adding 1 Aso
===
Patients Waiting
[1] Aso
[2] Elle
[3] Liz
[5] Ophra
[4] Mommy
[20] Zedder
[6] Sassy
[19] Xylo
[7] Tattle
[15] Ratner
===
Adding 8 Vinnie
===
Patients Waiting
[1] Aso
[2] Elle
[3] Liz
[5] Ophra
[4] Mommy
[20] Zedder
[6] Sassy
[19] Xylo
[7] Tattle
[15] Ratner
[8] Vinnie
===
We're CLOSING! Deleting patient queue!
Removing Aso from the queue.
Removing Elle from the queue.
Removing Liz from the queue.
Removing Ophra from the queue.
Removing Mommy from the queue.
Removing Zedder from the queue.
Removing Sassy from the queue.
Removing Xylo from the queue.
Removing Tattle from the queue.
Removing Ratner from the queue.
Removing Vinnie from the queue.
the provided driver -- Driver.cpp
#include
#include "PatientQueue.hpp"
using namespace std;
void processNextPatient(PatientQueue* queue);
int main()
{
PatientQueue *queue = new PatientQueue();
queue->enqueue(22, "Lila");
processNextPatient(queue);
queue->printList();
processNextPatient(queue);
queue->enqueue(3, "Liz");
queue->enqueue(19, "Xylo");
queue->enqueue(20, "Zedder");
queue->enqueue(15, "Ratner");
queue->enqueue(7, "Tattle");
queue->enqueue(6, "Sassy");
queue->enqueue(2, "Elle");
queue->enqueue(1, "Alph");
queue->enqueue(5, "Ophra");
queue->enqueue(4, "Mommy");
processNextPatient(queue);
cout << queue->size() << " patient" << (queue->size()==1?"":"s") << " currently
waiting." << endl;
queue->enqueue(1, "Aso");
queue->enqueue(8, "Vinnie");
delete queue;
return 0;
}
void processNextPatient(PatientQueue* queue)
{
if (queue == NULL)
{
cout << "No one waiting!" << endl;
}
else if (!queue->isEmpty())
{
Patient *next = queue->dequeue();
cout << "=== NEXT! - " << next->name << endl;
delete next;
}
}
the provided hpp file -- PatientQueue.hpp
//using namespace std;
struct Patient
{
int priority;
std::string name;
Patient(int _priority, std::string _name)
{
priority = _priority;
name = _name;
}
};
class PatientQueue
{
public:
PatientQueue();
~PatientQueue(); // release memory and delete queue
int size();
bool isEmpty();
void enqueue(int priority, std::string name);
Patient* dequeue(); // returns pointer to patient record and removes from array
void printList(); // print the array
private:
void swap(int index1, int index2); // swap the contents in the array
Patient *waitlist[100];
int lastIndex;
};
PriorityQueue.cpp I have made thus far
#include "PatientQueue.hpp"
#include
using namespace std;
PatientQueue::PatientQueue()
{
rear = NULL;
front = NULL;
}
PatientQueue::~PatientQueue() // release memory and delete queue
{
//stuff
}
int PatientQueue::size()
{
//stuff
}
bool PatientQueue::isEmpty()
{
//stuff
}
void PatientQueue::enqueue(int priority, std::string name)
{
Patient *temp = new Patient;
temp->priority = name;
temp->next = NULL;
if(front == NULL)
{
front = temp;
}
else
{
rear->next = temp;
}
rear = temp;
}
PatientQueue::Patient* dequeue() // returns pointer to patient record and removes from array
{
Patient *temp = new Patient;
if(front == NULL)
{
cout<<" Queue is Empty ";
}
else
{
temp = front;
front = front->next;
cout<<"The data Dequeued is "<priority;
delete temp;
}
}
void PatientQueue::printList() // print the array
{
Patient *p = new Patient;
p = front;
if(front == NULL)
{
cout<<" Nothing to Display ";
}
else
{
while(p!=NULL)
{
cout<priority;
p = p->next;
}
}
}
void PatientQueue::swap(int index1, int index2) // swap the contents in the array
{
int temp = list[index1];
list[index1] = list[index2];
list[index2] = temp;
}
PatientQueue::Patient *waitlist[100]
{
//stuff
}
int PatientQueue::lastIndex
{
//stuff
}
Solution
Here is the PatientQueue.cpp file contents
#include "PatientQueue.hpp"
#include
using namespace std;
PatientQueue::PatientQueue()
{
lastIndex = 0; //initialize the count
}
PatientQueue::~PatientQueue() // release memory and delete queue
{
for(int i = 0 ; i < lastIndex ; i++)
{
cout<<"Removing "<priority > waitlist[lastIndex]->priority)
swap(i,lastIndex);
lastIndex++;
cout<<"==="<priority<<"] "<name<

More Related Content

Similar to Priority Queue as a Heap ArrayEmergency Room Patient AdmittanceO.pdf

Computer Science class 12
Computer Science  class 12Computer Science  class 12
Computer Science class 12
Abhishek Sinha
 
Implement in C++Create a class named Doctor that has three member .pdf
Implement in C++Create a class named Doctor that has three member .pdfImplement in C++Create a class named Doctor that has three member .pdf
Implement in C++Create a class named Doctor that has three member .pdf
cronkwurphyb44502
 
MT_01_unittest_python.pdf
MT_01_unittest_python.pdfMT_01_unittest_python.pdf
MT_01_unittest_python.pdf
Hans Jones
 
Question I need help with c++ Simple Classes Assigment. i get this .pdf
Question I need help with c++ Simple Classes Assigment. i get this .pdfQuestion I need help with c++ Simple Classes Assigment. i get this .pdf
Question I need help with c++ Simple Classes Assigment. i get this .pdf
exxonzone
 
Kupdf.com 292609858 computer-science-c-project-on-hospital-management-system-...
Kupdf.com 292609858 computer-science-c-project-on-hospital-management-system-...Kupdf.com 292609858 computer-science-c-project-on-hospital-management-system-...
Kupdf.com 292609858 computer-science-c-project-on-hospital-management-system-...
Manjeet Maan
 
Hospital Managment System Project Proposal
Hospital Managment System Project ProposalHospital Managment System Project Proposal
Hospital Managment System Project Proposal
Azeemaj101
 
Disease Prediction And Doctor Appointment system
Disease Prediction And Doctor Appointment  systemDisease Prediction And Doctor Appointment  system
Disease Prediction And Doctor Appointment system
KOYELMAJUMDAR1
 
ECHOES_ConSPIC_2014_Write-Up_Korak_Datta
ECHOES_ConSPIC_2014_Write-Up_Korak_DattaECHOES_ConSPIC_2014_Write-Up_Korak_Datta
ECHOES_ConSPIC_2014_Write-Up_Korak_DattaKorak Datta
 
Create a menu-driven program that will accept a collection of non-ne.pdf
Create a menu-driven program that will accept a collection of non-ne.pdfCreate a menu-driven program that will accept a collection of non-ne.pdf
Create a menu-driven program that will accept a collection of non-ne.pdf
rajeshjangid1865
 
2 b queues
2 b queues2 b queues
2 b queues
Nguync91368
 
Healthcare Data Analytics Implementation
Healthcare Data Analytics ImplementationHealthcare Data Analytics Implementation
Healthcare Data Analytics Implementation
ALTEN Calsoft Labs
 
#include customer.h#include heap.h#include iostream.docx
#include customer.h#include heap.h#include iostream.docx#include customer.h#include heap.h#include iostream.docx
#include customer.h#include heap.h#include iostream.docx
AASTHA76
 
Congrats ! You got your Data Science Job
Congrats ! You got your Data Science JobCongrats ! You got your Data Science Job
Congrats ! You got your Data Science Job
Rohit Dubey
 
Data Structure Using C
Data Structure Using CData Structure Using C
Data Structure Using C
cpjcollege
 
Saude
SaudeSaude
Queue
QueueQueue
Unit 4 queue
Unit   4 queueUnit   4 queue
Unit 4 queue
Dabbal Singh Mahara
 

Similar to Priority Queue as a Heap ArrayEmergency Room Patient AdmittanceO.pdf (20)

Report On HMS
Report On HMSReport On HMS
Report On HMS
 
Computer Science class 12
Computer Science  class 12Computer Science  class 12
Computer Science class 12
 
Implement in C++Create a class named Doctor that has three member .pdf
Implement in C++Create a class named Doctor that has three member .pdfImplement in C++Create a class named Doctor that has three member .pdf
Implement in C++Create a class named Doctor that has three member .pdf
 
MT_01_unittest_python.pdf
MT_01_unittest_python.pdfMT_01_unittest_python.pdf
MT_01_unittest_python.pdf
 
Question I need help with c++ Simple Classes Assigment. i get this .pdf
Question I need help with c++ Simple Classes Assigment. i get this .pdfQuestion I need help with c++ Simple Classes Assigment. i get this .pdf
Question I need help with c++ Simple Classes Assigment. i get this .pdf
 
Kupdf.com 292609858 computer-science-c-project-on-hospital-management-system-...
Kupdf.com 292609858 computer-science-c-project-on-hospital-management-system-...Kupdf.com 292609858 computer-science-c-project-on-hospital-management-system-...
Kupdf.com 292609858 computer-science-c-project-on-hospital-management-system-...
 
Hospital Managment System Project Proposal
Hospital Managment System Project ProposalHospital Managment System Project Proposal
Hospital Managment System Project Proposal
 
Disease Prediction And Doctor Appointment system
Disease Prediction And Doctor Appointment  systemDisease Prediction And Doctor Appointment  system
Disease Prediction And Doctor Appointment system
 
ECHOES_ConSPIC_2014_Write-Up_Korak_Datta
ECHOES_ConSPIC_2014_Write-Up_Korak_DattaECHOES_ConSPIC_2014_Write-Up_Korak_Datta
ECHOES_ConSPIC_2014_Write-Up_Korak_Datta
 
Final Report
Final ReportFinal Report
Final Report
 
Create a menu-driven program that will accept a collection of non-ne.pdf
Create a menu-driven program that will accept a collection of non-ne.pdfCreate a menu-driven program that will accept a collection of non-ne.pdf
Create a menu-driven program that will accept a collection of non-ne.pdf
 
2 b queues
2 b queues2 b queues
2 b queues
 
Introduction to c part -1
Introduction to c   part -1Introduction to c   part -1
Introduction to c part -1
 
Healthcare Data Analytics Implementation
Healthcare Data Analytics ImplementationHealthcare Data Analytics Implementation
Healthcare Data Analytics Implementation
 
#include customer.h#include heap.h#include iostream.docx
#include customer.h#include heap.h#include iostream.docx#include customer.h#include heap.h#include iostream.docx
#include customer.h#include heap.h#include iostream.docx
 
Congrats ! You got your Data Science Job
Congrats ! You got your Data Science JobCongrats ! You got your Data Science Job
Congrats ! You got your Data Science Job
 
Data Structure Using C
Data Structure Using CData Structure Using C
Data Structure Using C
 
Saude
SaudeSaude
Saude
 
Queue
QueueQueue
Queue
 
Unit 4 queue
Unit   4 queueUnit   4 queue
Unit 4 queue
 

More from seamusschwaabl99557

Note the structures through which light passes to reach the retina. W.pdf
Note the structures through which light passes to reach the retina. W.pdfNote the structures through which light passes to reach the retina. W.pdf
Note the structures through which light passes to reach the retina. W.pdf
seamusschwaabl99557
 
Muriel recently stopped taking her medication resulting in flulike s.pdf
Muriel recently stopped taking her medication resulting in flulike s.pdfMuriel recently stopped taking her medication resulting in flulike s.pdf
Muriel recently stopped taking her medication resulting in flulike s.pdf
seamusschwaabl99557
 
managerial reporting systems areStandardizedRigidFlexible.pdf
managerial reporting systems areStandardizedRigidFlexible.pdfmanagerial reporting systems areStandardizedRigidFlexible.pdf
managerial reporting systems areStandardizedRigidFlexible.pdf
seamusschwaabl99557
 
Lot X_1, ..., X_n be independent and identically distributed continuo.pdf
Lot X_1, ..., X_n be independent and identically distributed continuo.pdfLot X_1, ..., X_n be independent and identically distributed continuo.pdf
Lot X_1, ..., X_n be independent and identically distributed continuo.pdf
seamusschwaabl99557
 
Let Y follows a Poisson distribution with mean lambda that is, Y app.pdf
Let Y follows a Poisson distribution with mean lambda that is, Y app.pdfLet Y follows a Poisson distribution with mean lambda that is, Y app.pdf
Let Y follows a Poisson distribution with mean lambda that is, Y app.pdf
seamusschwaabl99557
 
In humans, the HOXD homeotic gene cluster plays a critical role in l.pdf
In humans, the HOXD homeotic gene cluster plays a critical role in l.pdfIn humans, the HOXD homeotic gene cluster plays a critical role in l.pdf
In humans, the HOXD homeotic gene cluster plays a critical role in l.pdf
seamusschwaabl99557
 
I am sorry but my major does not cover programming in depth (ICT) an.pdf
I am sorry but my major does not cover programming in depth (ICT) an.pdfI am sorry but my major does not cover programming in depth (ICT) an.pdf
I am sorry but my major does not cover programming in depth (ICT) an.pdf
seamusschwaabl99557
 
explain why blockage or removal of the lymphatic vessels can result .pdf
explain why blockage or removal of the lymphatic vessels can result .pdfexplain why blockage or removal of the lymphatic vessels can result .pdf
explain why blockage or removal of the lymphatic vessels can result .pdf
seamusschwaabl99557
 
Describe three different symbiotic relationships, with examples. Whi.pdf
Describe three different symbiotic relationships, with examples. Whi.pdfDescribe three different symbiotic relationships, with examples. Whi.pdf
Describe three different symbiotic relationships, with examples. Whi.pdf
seamusschwaabl99557
 
Describe the differences seen in the hydra, planarian, clam, grasshop.pdf
Describe the differences seen in the hydra, planarian, clam, grasshop.pdfDescribe the differences seen in the hydra, planarian, clam, grasshop.pdf
Describe the differences seen in the hydra, planarian, clam, grasshop.pdf
seamusschwaabl99557
 
Companyhas prot s Price per unit Variable cost per unit Fixed costs p.pdf
Companyhas prot s Price per unit Variable cost per unit Fixed costs p.pdfCompanyhas prot s Price per unit Variable cost per unit Fixed costs p.pdf
Companyhas prot s Price per unit Variable cost per unit Fixed costs p.pdf
seamusschwaabl99557
 
Alice Agent is an employee of Patti Principal. She negligently runs .pdf
Alice Agent is an employee of Patti Principal. She negligently runs .pdfAlice Agent is an employee of Patti Principal. She negligently runs .pdf
Alice Agent is an employee of Patti Principal. She negligently runs .pdf
seamusschwaabl99557
 
at log kHz SolutionYou can have several problems 1) if you a.pdf
at log kHz SolutionYou can have several problems 1) if you a.pdfat log kHz SolutionYou can have several problems 1) if you a.pdf
at log kHz SolutionYou can have several problems 1) if you a.pdf
seamusschwaabl99557
 
Bark, which is thicken, toughen periderm, arises from this lateral m.pdf
Bark, which is thicken, toughen periderm, arises from this lateral m.pdfBark, which is thicken, toughen periderm, arises from this lateral m.pdf
Bark, which is thicken, toughen periderm, arises from this lateral m.pdf
seamusschwaabl99557
 
Why do you think it is usually preferable to start with the side con.pdf
Why do you think it is usually preferable to start with the side con.pdfWhy do you think it is usually preferable to start with the side con.pdf
Why do you think it is usually preferable to start with the side con.pdf
seamusschwaabl99557
 
Why is the mucus thicker than normal in CF patients A good answer w.pdf
Why is the mucus thicker than normal in CF patients A good answer w.pdfWhy is the mucus thicker than normal in CF patients A good answer w.pdf
Why is the mucus thicker than normal in CF patients A good answer w.pdf
seamusschwaabl99557
 
Which of the following primordial reproductive structures is NOT ext.pdf
Which of the following primordial reproductive structures is NOT ext.pdfWhich of the following primordial reproductive structures is NOT ext.pdf
Which of the following primordial reproductive structures is NOT ext.pdf
seamusschwaabl99557
 
what kind of accessory protein would you classify IRS1 and 2 as.pdf
what kind of accessory protein would you classify IRS1 and 2 as.pdfwhat kind of accessory protein would you classify IRS1 and 2 as.pdf
what kind of accessory protein would you classify IRS1 and 2 as.pdf
seamusschwaabl99557
 
What is the main difference between prokaryotic and eukaryotic riboso.pdf
What is the main difference between prokaryotic and eukaryotic riboso.pdfWhat is the main difference between prokaryotic and eukaryotic riboso.pdf
What is the main difference between prokaryotic and eukaryotic riboso.pdf
seamusschwaabl99557
 
what is the cardinality of a sample spaceSolutionA sample spa.pdf
what is the cardinality of a sample spaceSolutionA sample spa.pdfwhat is the cardinality of a sample spaceSolutionA sample spa.pdf
what is the cardinality of a sample spaceSolutionA sample spa.pdf
seamusschwaabl99557
 

More from seamusschwaabl99557 (20)

Note the structures through which light passes to reach the retina. W.pdf
Note the structures through which light passes to reach the retina. W.pdfNote the structures through which light passes to reach the retina. W.pdf
Note the structures through which light passes to reach the retina. W.pdf
 
Muriel recently stopped taking her medication resulting in flulike s.pdf
Muriel recently stopped taking her medication resulting in flulike s.pdfMuriel recently stopped taking her medication resulting in flulike s.pdf
Muriel recently stopped taking her medication resulting in flulike s.pdf
 
managerial reporting systems areStandardizedRigidFlexible.pdf
managerial reporting systems areStandardizedRigidFlexible.pdfmanagerial reporting systems areStandardizedRigidFlexible.pdf
managerial reporting systems areStandardizedRigidFlexible.pdf
 
Lot X_1, ..., X_n be independent and identically distributed continuo.pdf
Lot X_1, ..., X_n be independent and identically distributed continuo.pdfLot X_1, ..., X_n be independent and identically distributed continuo.pdf
Lot X_1, ..., X_n be independent and identically distributed continuo.pdf
 
Let Y follows a Poisson distribution with mean lambda that is, Y app.pdf
Let Y follows a Poisson distribution with mean lambda that is, Y app.pdfLet Y follows a Poisson distribution with mean lambda that is, Y app.pdf
Let Y follows a Poisson distribution with mean lambda that is, Y app.pdf
 
In humans, the HOXD homeotic gene cluster plays a critical role in l.pdf
In humans, the HOXD homeotic gene cluster plays a critical role in l.pdfIn humans, the HOXD homeotic gene cluster plays a critical role in l.pdf
In humans, the HOXD homeotic gene cluster plays a critical role in l.pdf
 
I am sorry but my major does not cover programming in depth (ICT) an.pdf
I am sorry but my major does not cover programming in depth (ICT) an.pdfI am sorry but my major does not cover programming in depth (ICT) an.pdf
I am sorry but my major does not cover programming in depth (ICT) an.pdf
 
explain why blockage or removal of the lymphatic vessels can result .pdf
explain why blockage or removal of the lymphatic vessels can result .pdfexplain why blockage or removal of the lymphatic vessels can result .pdf
explain why blockage or removal of the lymphatic vessels can result .pdf
 
Describe three different symbiotic relationships, with examples. Whi.pdf
Describe three different symbiotic relationships, with examples. Whi.pdfDescribe three different symbiotic relationships, with examples. Whi.pdf
Describe three different symbiotic relationships, with examples. Whi.pdf
 
Describe the differences seen in the hydra, planarian, clam, grasshop.pdf
Describe the differences seen in the hydra, planarian, clam, grasshop.pdfDescribe the differences seen in the hydra, planarian, clam, grasshop.pdf
Describe the differences seen in the hydra, planarian, clam, grasshop.pdf
 
Companyhas prot s Price per unit Variable cost per unit Fixed costs p.pdf
Companyhas prot s Price per unit Variable cost per unit Fixed costs p.pdfCompanyhas prot s Price per unit Variable cost per unit Fixed costs p.pdf
Companyhas prot s Price per unit Variable cost per unit Fixed costs p.pdf
 
Alice Agent is an employee of Patti Principal. She negligently runs .pdf
Alice Agent is an employee of Patti Principal. She negligently runs .pdfAlice Agent is an employee of Patti Principal. She negligently runs .pdf
Alice Agent is an employee of Patti Principal. She negligently runs .pdf
 
at log kHz SolutionYou can have several problems 1) if you a.pdf
at log kHz SolutionYou can have several problems 1) if you a.pdfat log kHz SolutionYou can have several problems 1) if you a.pdf
at log kHz SolutionYou can have several problems 1) if you a.pdf
 
Bark, which is thicken, toughen periderm, arises from this lateral m.pdf
Bark, which is thicken, toughen periderm, arises from this lateral m.pdfBark, which is thicken, toughen periderm, arises from this lateral m.pdf
Bark, which is thicken, toughen periderm, arises from this lateral m.pdf
 
Why do you think it is usually preferable to start with the side con.pdf
Why do you think it is usually preferable to start with the side con.pdfWhy do you think it is usually preferable to start with the side con.pdf
Why do you think it is usually preferable to start with the side con.pdf
 
Why is the mucus thicker than normal in CF patients A good answer w.pdf
Why is the mucus thicker than normal in CF patients A good answer w.pdfWhy is the mucus thicker than normal in CF patients A good answer w.pdf
Why is the mucus thicker than normal in CF patients A good answer w.pdf
 
Which of the following primordial reproductive structures is NOT ext.pdf
Which of the following primordial reproductive structures is NOT ext.pdfWhich of the following primordial reproductive structures is NOT ext.pdf
Which of the following primordial reproductive structures is NOT ext.pdf
 
what kind of accessory protein would you classify IRS1 and 2 as.pdf
what kind of accessory protein would you classify IRS1 and 2 as.pdfwhat kind of accessory protein would you classify IRS1 and 2 as.pdf
what kind of accessory protein would you classify IRS1 and 2 as.pdf
 
What is the main difference between prokaryotic and eukaryotic riboso.pdf
What is the main difference between prokaryotic and eukaryotic riboso.pdfWhat is the main difference between prokaryotic and eukaryotic riboso.pdf
What is the main difference between prokaryotic and eukaryotic riboso.pdf
 
what is the cardinality of a sample spaceSolutionA sample spa.pdf
what is the cardinality of a sample spaceSolutionA sample spa.pdfwhat is the cardinality of a sample spaceSolutionA sample spa.pdf
what is the cardinality of a sample spaceSolutionA sample spa.pdf
 

Recently uploaded

JEE1_This_section_contains_FOUR_ questions
JEE1_This_section_contains_FOUR_ questionsJEE1_This_section_contains_FOUR_ questions
JEE1_This_section_contains_FOUR_ questions
ShivajiThube2
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Akanksha trivedi rama nursing college kanpur.
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
Scholarhat
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
Multithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race conditionMultithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race condition
Mohammed Sikander
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
EduSkills OECD
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
Advantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO PerspectiveAdvantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO Perspective
Krisztián Száraz
 
Normal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of LabourNormal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of Labour
Wasim Ak
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
David Douglas School District
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
vaibhavrinwa19
 
Best Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDABest Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDA
deeptiverma2406
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
chanes7
 

Recently uploaded (20)

JEE1_This_section_contains_FOUR_ questions
JEE1_This_section_contains_FOUR_ questionsJEE1_This_section_contains_FOUR_ questions
JEE1_This_section_contains_FOUR_ questions
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 
Multithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race conditionMultithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race condition
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
Advantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO PerspectiveAdvantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO Perspective
 
Normal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of LabourNormal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of Labour
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
 
Best Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDABest Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDA
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
 

Priority Queue as a Heap ArrayEmergency Room Patient AdmittanceO.pdf

  • 1. Priority Queue as a Heap Array Emergency Room Patient Admittance Objectives • Build a priority queue as a heap stored in an array • Dequeue the next priority item and maintaining the heap For this assignment, you will be implementing a class of your own: a priority queue, which is a variation on the standard queue. The standard queue processes element in the first-in, first-out ("FIFO") manner typical of ordinary waiting lines. Queues can be handy, but a FIFO strategy isn't always what's needed. A hospital emergency room, for example, needs to schedule patients according to priority. A patient with a more critical problem will pre-empt others even if they have been waiting longer. This is a priority queue, where elements are prioritized relative to each other and when asked to dequeue one, it is the highest priority element in the queue that is removed. The priority queue will store a collection of structs that keep track of the patient name and an integer for the priority. Smaller integers are considered higher priority than larger ones and are dequeued ahead of larger values. The header file is provided with a struct to maintain the patient information and a class to maintain the priority queue. In this example, assume all priority numbers are unique (in a real ER program, the numbers may be from 1 to 10 plus the date/time stamp to determine who came in first when multiple have the same priority). Specifications • Use the provided header file – do not change in any way! • Test your program with the provided driver program – without changing the driver program your output should match what is provided below. Expected Output From the provided driver program, your output should appear as follows: Adding 22 Lila === Patients Waiting [22] Lila === Processing 22 Lila === NEXT! - Lila
  • 2. === Patients Waiting No one waiting! === Adding 3 Liz === Patients Waiting [3] Liz === Adding 19 Xylo === Patients Waiting [3] Liz [19] Xylo === Adding 20 Zedder === Patients Waiting [3] Liz [19] Xylo [20] Zedder === Adding 15 Ratner === Patients Waiting [3] Liz [15] Ratner [20] Zedder [19] Xylo === Adding 7 Tattle === Patients Waiting [3] Liz [7] Tattle [20] Zedder
  • 3. [19] Xylo [15] Ratner === Adding 6 Sassy === Patients Waiting [3] Liz [7] Tattle [6] Sassy [19] Xylo [15] Ratner [20] Zedder === Adding 2 Elle === Patients Waiting [2] Elle [7] Tattle [3] Liz [19] Xylo [15] Ratner [20] Zedder [6] Sassy === Adding 1 Alph === Patients Waiting [1] Alph [2] Elle [3] Liz [7] Tattle [15] Ratner [20] Zedder [6] Sassy [19] Xylo ===
  • 4. Adding 5 Ophra === Patients Waiting [1] Alph [2] Elle [3] Liz [5] Ophra [15] Ratner [20] Zedder [6] Sassy [19] Xylo [7] Tattle === Adding 4 Mommy === Patients Waiting [1] Alph [2] Elle [3] Liz [5] Ophra [4] Mommy [20] Zedder [6] Sassy [19] Xylo [7] Tattle [15] Ratner === Processing 1 Alph === NEXT! - Alph 9 patients currently waiting. Adding 1 Aso === Patients Waiting [1] Aso [2] Elle
  • 5. [3] Liz [5] Ophra [4] Mommy [20] Zedder [6] Sassy [19] Xylo [7] Tattle [15] Ratner === Adding 8 Vinnie === Patients Waiting [1] Aso [2] Elle [3] Liz [5] Ophra [4] Mommy [20] Zedder [6] Sassy [19] Xylo [7] Tattle [15] Ratner [8] Vinnie === We're CLOSING! Deleting patient queue! Removing Aso from the queue. Removing Elle from the queue. Removing Liz from the queue. Removing Ophra from the queue. Removing Mommy from the queue. Removing Zedder from the queue. Removing Sassy from the queue. Removing Xylo from the queue. Removing Tattle from the queue. Removing Ratner from the queue. Removing Vinnie from the queue.
  • 6. the provided driver -- Driver.cpp #include #include "PatientQueue.hpp" using namespace std; void processNextPatient(PatientQueue* queue); int main() { PatientQueue *queue = new PatientQueue(); queue->enqueue(22, "Lila"); processNextPatient(queue); queue->printList(); processNextPatient(queue); queue->enqueue(3, "Liz"); queue->enqueue(19, "Xylo"); queue->enqueue(20, "Zedder"); queue->enqueue(15, "Ratner"); queue->enqueue(7, "Tattle"); queue->enqueue(6, "Sassy"); queue->enqueue(2, "Elle"); queue->enqueue(1, "Alph"); queue->enqueue(5, "Ophra"); queue->enqueue(4, "Mommy"); processNextPatient(queue); cout << queue->size() << " patient" << (queue->size()==1?"":"s") << " currently waiting." << endl; queue->enqueue(1, "Aso"); queue->enqueue(8, "Vinnie"); delete queue; return 0; } void processNextPatient(PatientQueue* queue) { if (queue == NULL) { cout << "No one waiting!" << endl; }
  • 7. else if (!queue->isEmpty()) { Patient *next = queue->dequeue(); cout << "=== NEXT! - " << next->name << endl; delete next; } } the provided hpp file -- PatientQueue.hpp //using namespace std; struct Patient { int priority; std::string name; Patient(int _priority, std::string _name) { priority = _priority; name = _name; } }; class PatientQueue { public: PatientQueue(); ~PatientQueue(); // release memory and delete queue int size(); bool isEmpty(); void enqueue(int priority, std::string name); Patient* dequeue(); // returns pointer to patient record and removes from array void printList(); // print the array private: void swap(int index1, int index2); // swap the contents in the array Patient *waitlist[100]; int lastIndex; };
  • 8. PriorityQueue.cpp I have made thus far #include "PatientQueue.hpp" #include using namespace std; PatientQueue::PatientQueue() { rear = NULL; front = NULL; } PatientQueue::~PatientQueue() // release memory and delete queue { //stuff } int PatientQueue::size() { //stuff } bool PatientQueue::isEmpty() { //stuff } void PatientQueue::enqueue(int priority, std::string name) { Patient *temp = new Patient; temp->priority = name; temp->next = NULL; if(front == NULL) { front = temp; } else { rear->next = temp; } rear = temp; }
  • 9. PatientQueue::Patient* dequeue() // returns pointer to patient record and removes from array { Patient *temp = new Patient; if(front == NULL) { cout<<" Queue is Empty "; } else { temp = front; front = front->next; cout<<"The data Dequeued is "<priority; delete temp; } } void PatientQueue::printList() // print the array { Patient *p = new Patient; p = front; if(front == NULL) { cout<<" Nothing to Display "; } else { while(p!=NULL) { cout<priority; p = p->next; } } } void PatientQueue::swap(int index1, int index2) // swap the contents in the array { int temp = list[index1]; list[index1] = list[index2];
  • 10. list[index2] = temp; } PatientQueue::Patient *waitlist[100] { //stuff } int PatientQueue::lastIndex { //stuff } Solution Here is the PatientQueue.cpp file contents #include "PatientQueue.hpp" #include using namespace std; PatientQueue::PatientQueue() { lastIndex = 0; //initialize the count } PatientQueue::~PatientQueue() // release memory and delete queue { for(int i = 0 ; i < lastIndex ; i++) { cout<<"Removing "<priority > waitlist[lastIndex]->priority) swap(i,lastIndex); lastIndex++; cout<<"==="<priority<<"] "<name<