Skip to content

assignment 5  #2

@Haotian-Shi-cyber

Description

@Haotian-Shi-cyber
void LinkedListPatientQueue::upgradePatient(string name, int newPriority) {
    if (front == nullptr) { //error case
        throw("Invalid Operation: The queue of patients is empty.");
    } else {
        PatientNode* current = front;
        while (current->next != nullptr && current->next->name != name) {
            current = current->next;
        }
        if (current->next == nullptr) { //error case
            throw("Invalid Operation: There is no patient with the given name.");
        } else {
            PatientNode* toModify = current->next;
            if (toModify->priority < newPriority) { //error case
                throw("Invalid Operation: The priority of the patient is already greater than the"
                " new priority.");
            } else {
                current->next = toModify->next;
                newPatient(toModify->name, newPriority);
                delete toModify; //preventing memory leak.
            }
        }
    }
}

in linked list implementation cpp file, function upgradepatient, this code doesn't consider when you want to change the priority of frontname, an error would generate.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions