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)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.