USE PYTHON TO SOLVE THIS PROBLEM!! USE THIS CODE TEMPLATE!!

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

USE PYTHON TO SOLVE THIS PROBLEM!!

USE THIS CODE TEMPLATE!!

class Patient:
    def __init__(self, name, priority):
        """Initialization of the Patient object

        Args:
            name (string): The name of the patient, consists of alphabetical characters only.
            priority (int): The integer priority of the patient, from 1 to 4.
        """
        self.name = name
        self.priority = priority


class PriorityQueue:
    def __init__(self):
        """Initialize the priority queue. It is up to you what kind of data structure you will use."""
        # Part A. Implement initialization of your priority queue

    def insert(self, patient):
        """Insert a new patient in the priority queue

        Args:
            patient (Patient): Inserts a new Patient object, defined above,
        """
        # Part B. Implement code for insertion

    def pop_highest_priority(self):
        """A combination of get highest priority and delete highest priority. This should return the next person in line if they exist otherwise, this should return an empty string ("").

        Returns:
            string: Return either a patient name or an empty string ("").
        """
        # Part C. Implement popping of the highest priority

    def print_queue(self):
        """Print out the remainining patients in queue in order. Print out one patient name per line"""
        # Part D. Implement printing of the priority queue order


#### DO NOT MODIFY THE MAIN FUNCTION ####
if __name__ == "__main__":
    n = int(input())

    pq = PriorityQueue()

    print("Patients served:")
    for i in range(n):
        line = input()
        if line.isnumeric():
            patients_to_be_served = int(line)
            for i in range(patients_to_be_served):
                patient_name = pq.pop_highest_priority()
                if (
                    patient_name != ""
                ):  # If returned element is an empty string, then there are no more people in line so do not print
                    print(patient_name)
        else:
            name, priority = line.split(",")
            p = Patient(name, int(priority))
            pq.insert(p)

    print("Remaining:")
    pq.print_queue()

priority queue based on this classification with 1 being the highest priority and 4 being the lowest priority.
You may use any implementation of the priority queue.
HINT: You only have 4 levels of priority, you may simplify your implementation using prior programming
knowledge.
Input Format
For the first line, n, we indicate the number of input lines that follows.
The subsequent lines may have two different format as follows.
1. name,priority- The name of the patient and their priority that will be inserted in your priority queue.
2. m- The number of patients that can be served by attending physicians. This means that you will remove
the top-m patients from your priority queue.
Constraints
1. Name of the patients are composed of alphabetical characters only.
2.1 s priority s 4. If two patients have equal priority, then you should serve them chronologically.
3.0sn< 100
4. 0sm< 100. Note if m > len(priority_queue), then you should only serve the current people in line and
should not be applied proactively.
Output Format
The main function will be printing out patients served in order and after the input is done, it will print out the
remaining patients in the queue in order of priority.
Sample Input 0
Ferdie,3
Rangel,3
Williard,1
2
Herlan, 2
Marcus,1
1
Darvy, 4
Sample Output 0
Patients served:
williard
Ferdie
Marcus
Remaining:
Herlan
Rangel
Darvy
Transcribed Image Text:priority queue based on this classification with 1 being the highest priority and 4 being the lowest priority. You may use any implementation of the priority queue. HINT: You only have 4 levels of priority, you may simplify your implementation using prior programming knowledge. Input Format For the first line, n, we indicate the number of input lines that follows. The subsequent lines may have two different format as follows. 1. name,priority- The name of the patient and their priority that will be inserted in your priority queue. 2. m- The number of patients that can be served by attending physicians. This means that you will remove the top-m patients from your priority queue. Constraints 1. Name of the patients are composed of alphabetical characters only. 2.1 s priority s 4. If two patients have equal priority, then you should serve them chronologically. 3.0sn< 100 4. 0sm< 100. Note if m > len(priority_queue), then you should only serve the current people in line and should not be applied proactively. Output Format The main function will be printing out patients served in order and after the input is done, it will print out the remaining patients in the queue in order of priority. Sample Input 0 Ferdie,3 Rangel,3 Williard,1 2 Herlan, 2 Marcus,1 1 Darvy, 4 Sample Output 0 Patients served: williard Ferdie Marcus Remaining: Herlan Rangel Darvy
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY