Question: can I get help fixing these codes. I have to remove all the 2's from the linked list recursively //****************************************** list.h************************** struct node { int

can I get help fixing these codes. I have to remove all the 2's from the linked list recursively

//****************************************** list.h************************** struct node { int data; node * next; };

class list { public: //These functions are already written for you list(); //supplied ~list(); //supplied void build(); //supplied void display(); //supplied /* *****************YOUR TURN! ******************************** */ //Write your function prototype here: int removeTwo(); int removeTwo( node *& head);

int removeTwo(node *& head, node *& tail);

private: //notice there is both a head and a tail! node * head; node * tail; };

/*********************************** function.cpp**********************************

#include "list.h"

int list::removeTwo() { if(!head) return 0; else return removeTwo(head, tail); }

int list::removeTwo(node *& head, node *& tail) { if(head->next != tail) { if(head->next->data == 2) { node * temp = new node; temp->next = NULL; temp = head->next; head->next = temp->next; delete temp; return removeTwo(head->next,tail); } else return removeTwo(head->next, tail); } if(tail->data == 2) { delete tail; } else return removeTwo( head->next, tail);

} */

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!