write this from iterative to recursive in cppSolutionHi Plea

write this from iterative to recursive in cpp

Solution

Hi, Please find my implementation.

Please let me know in case of any issue.

void Queue::findRemoveRec(int num){

// base case
if(head==NULL)
{
std::cout<<\"empty\"<<std::endl;
}
else if(head->next==NULL || head->data==num)
{
if(head->data==num)
{
Node *temp = head;
head = head->next;
delete temp;
}
else{
std::cout<<\"item:\"<<num<<\"not found\"<<std::endl;
}
}else{

// recursive util function call
findRemoveRecUtil(head, num);
}
}

void Queue::findRemoveRec(Node *item, int num){

// base case
if(item == NULL || item->next == NULL){
std::cout<<\"no items:\"<<num<<\"not found\"<<std::endl;
return;
}

// if next node has same value equal to num
if(item->next->data == num){
item->next = item->next->next
delete item->next;
return;
}

// calling recursive
findRemoveRecUtil(item->next, num);
}

write this from iterative to recursive in cppSolutionHi, Please find my implementation. Please let me know in case of any issue. void Queue::findRemoveRec(int n

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site