Explore BrainMass

Erase all occurrences of a target in linked list

This content was STOLEN from BrainMass.com - View the original, and get the already-completed solution here!

Extend the function eraseValue() to erase all occurrences of "target" in the linked list.

template < typename T >
void eraseAll (node * & front, const T& target);

This is the implementation of eraseValue() that must be modified.

node< T > *curr = front, *prev = NULL;
bool foundItem = false;

while (curr != NULL && !foundItem )
if (curr->nodeValue == target)
if (prev == NULL)
front = front -> next;
prev->next = curr-> next;
delete curr;
foundItem = true;
prev = curr;
curr = curr-> next;

© BrainMass Inc. brainmass.com October 25, 2018, 1:37 am ad1c9bdddf

Solution Preview

To erase all occurences of "target" in the linked list, you need to make following modifications to the given code.

1. Change "while (curr != NULL && !foundItem )" to "while (curr != NULL)" so that entire linked list is scanned for target value, rather than just stopping after finding first ...

Solution Summary

The solution first mentions what needs to be modified in eraseValue function to extend it to eraseAll function, and then gives the code for eraseAll function.

See Also This Related BrainMass Solution

Classroom management with students with special needs

I have to write 500 words on classroom management and the importance of it especially when dealing with special needs kids. I have attached some of the information I have found thus far. But it all needs to tie in and talk about the components of classroom management. Please help get me started.

View Full Posting Details