Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a definition for this function in the LinkedList.cpp source file that conf

ID: 3916781 • Letter: W

Question

Write a definition for this function in the LinkedList.cpp source file that conforms to the following pseudocode:

if the list is empty

    return false;
create Node pointer named curr that is initialized to head

while curr is not nullptr

    if curr->value == after_val

         create Node pointer named new_node that is initialized to a new
                         node whose value is initialized to insert_value
         assign curr->next to new_node->next (new_node->next = curr->next)
         assign new_node to curr->next (curr->next = new_node)
         if curr == tail

              assign new_node to tail (tail = new_node)

         return true

    else assign curr->next to curr (curr=curr->next)

return false (as after_val was not found)

if the list is empty

    return false;
create Node pointer named curr that is initialized to head

while curr is not nullptr

    if curr->value == after_val

         create Node pointer named new_node that is initialized to a new
                         node whose value is initialized to insert_value
         assign curr->next to new_node->next (new_node->next = curr->next)
         assign new_node to curr->next (curr->next = new_node)
         if curr == tail

              assign new_node to tail (tail = new_node)

         return true

    else assign curr->next to curr (curr=curr->next)

return false (as after_val was not found)

Explanation / Answer

bool insert_after(int after_val, int insert_value)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote