Write pseudocode (or actual code, if you want) for the following functions: 1. b
ID: 3899524 • Letter: W
Question
Write pseudocode (or actual code, if you want) for the following functions: 1. bool removeValue (int value) . This function will "remove" the first Node it finds with the given value that is not already deleted. (To "remove", it will only mark that Node as deleted.) If it does not find the value, it will return false without removing any Node. 2. bool removeAllValue (int value) . This function will "remove" all Nodes it finds with the given value by marking them as deleted. If it does not find the value, it will return false without removing any Node. Implement it in two ways: by reusing removeValue and by not using removeValue. 3. Imagine we have 1024 nodes, and the last 24 of them match. We call each of our removeAllValue functions. a. Approximately how many Nodes would we visit using the version that reuses removeValue? b. Approximately how many Nodes would we visit if we didn't reuse removeValue? C. Is it always best to reuse code?--Explanation / Answer
1. bool removeValue(int value)
{
Node * p=head;
bool f=false;
if(head->data==value){
head=p=p->next;
free(p);
f=true;
}
while( p->next!=NULL)
{
if(p->next->data==value)
{
Node *ptr=p->next;
p->next=p->next->next;
free(ptr);
f=true;
}
p=p->next;
}
return f;
}
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.