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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started