Question: Implement the removeValue function of the LinkedList class . bool LinkedList::removeValue(int d) The job of this function is to remove d from the list. There

Implement the removeValue function of the LinkedList class .

bool LinkedList::removeValue(int d)

The job of this function is to remove d from the list. There are two cases to consider: either d occurs in the linked list or it doesn't. If d does occur, then the first node containing d should be removed. Also, length should be decremented and the value true should be returned. If d doesn't occur in the list, then the function will simply return false and leave the list unaltered.

Hint: First check if the list is empty and return false in that case. If the list is nonempty, check if the head node contains d. If it does then just call removeFirst(). If the head node doesn't contain d then call findPre(d) and save the result in a variable called pre. If pre->next is null then just return false . If pre->next isn't null then call removeAfter(pre) to remove the node. Also return true in this case.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!