Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need help fixing the recursion to this code. I attempted the solution below on IntegerLinkedList.cpp, however, I can't seem to figure it out. The missing

Need help fixing the recursion to this code. I attempted the solution below on IntegerLinkedList.cpp, however, I can't seem to figure it out. The missing part of the code prob3.cpp is given to us which is basically testing the following two codes below that I need help figuring out. We are to recursively return true or false if any of the numbers in the array are in fact a positive number. For example: -2 -30 -22 -12 4 -99 would return True. while: -12 -67 -54 -23 -1 -6 would return False. ************************************************************************************************************************************************ IntengerLinkedList.h  #pragma once class SNode { public: int elem; SNode *next; }; class IntegerLinkedList { private: SNode *head; bool checkRecurse (SNode *ptr); // for Problem 3; Implement in prob3.cpp public: IntegerLinkedList(): head(nullptr) {} void addFront(int x); // recursion helper function called from main for PROBLEM 3 bool checkRecurseHelper (); };
 ************************************************************************************************************************************************ IntegerLinkedList.cpp  #include "IntegerLinkedList.h" #include "prob3.cpp" bool IntegerLinkedList::checkRecurse (SNode *ptr) { // COMPLETE THIS FOR PROBLEM 3 if(ptr == nullptr) return 0; //return ptr->elem + checkRecurse(ptr->next); //TESTING THIS if((checkRecurse(ptr->next) >= 1)) //TRIED TO GO THROUGH LINKE LIST return false; // IF A NUBMER WAS POSITIVE IT WOULD RETURN THE FALSE // OTHERWISE IT WOULD BE TRUE. return true; } void IntegerLinkedList::addFront(int x) { SNode *tmp = head; head = new SNode; head->next = tmp; head->elem = x; } // recursion helper function called from main for PROBLEM 3 bool IntegerLinkedList::checkRecurseHelper () { return checkRecurse(head); }

***********************************************************************************************************************************************************************************************************

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions