Extend the function erasevalue to erase all occurrences of


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;
}
else
{
prev->next = curr-> next;
delete curr;
foundItem = true;
}
}
else
{
prev = curr;
curr = curr-> next;
}
}

Solution Preview :

Prepared by a verified Expert
Data Structure & Algorithms: Extend the function erasevalue to erase all occurrences of
Reference No:- TGS01257780

Now Priced at $20 (50% Discount)

Recommended (98%)

Rated (4.3/5)