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

// FILE: node1.h (part of the namespace main_savitch 5) // PROVIDES: A class for

ID: 3859133 • Letter: #

Question

// FILE: node1.h (part of the namespace main_savitch 5) // PROVIDES: A class for a node in a linked list and a collection of functions for // manipulating linked lists 2 // TYPEDEF for the node class // Each node of the list contains a piece of data and a pointer to the next node. The // type of the data is defined as node::value type in a typedef statement. The value_type // may be any of the C++ built-in types (int, char, etc.), or a class with a default constructor, // a copy constructor, an assignment operator, and a test for equality. 3 /I CONSTRUCTOR for the node class: // node(const value_type& init_data, node* initlink) // Postcondition: The node contains the specified data and link. //NOTE: The init_data parameter has a default value that is obtained from the default //constructor of the value_type. In the ANSI/ISO Standard, this notation is also allowed //for the built-in types, providing a default value of zero. The initlink has a default / value of NULL (continued)

Explanation / Answer

Given below is the function for removing all repetitions of the target item from a list. Please rate the answer if it helped. Thank you.

void list_delete_duplicates(node* &head_ptr, const node::value_type &target)
{
node *prev = NULL, *curr = head;
  
while(curr != NULL)
{
if(curr->data() == target) //if the current node has a matching target
{
if(curr == head_ptr) //if its the head node
list_head_remove(head_ptr);
else
list_remove(prev);
  
curr = prev->link(); //get the updated current node next to previous
}
else
{
prev = curr;
curr = curr->link();
}
}