Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

assignment 5 #2

Open
Haotian-Shi-cyber opened this issue Jul 2, 2021 · 0 comments
Open

assignment 5 #2

Haotian-Shi-cyber opened this issue Jul 2, 2021 · 0 comments

Comments

@Haotian-Shi-cyber
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant