Question
C++ Help. PLEASE COMMENT. PLEASE make as simple as possible. The following sequential search algorithm is non-recursive. Write and implement a recursive version of this
C++ Help. PLEASE COMMENT. PLEASE make as simple as possible.
The following sequential search algorithm is non-recursive. Write and implement a recursive version of this sequential search algorithm.
int seqSearch(const int list[], int listLength, int searchItem)
{
int loc;
bool found = false;
loc = 0;
while( loc { if(list[loc] == searchItem) found = true; else loc++; if( found ) return loc; else return -1; } } Use the following driver program to test your implementation: #include using namespace std; int recSequentialSearch(const int list[], int length, int item); int main() { int list[15] = {2, 6, 8, 23, 45, 43, 51, 62, 83, 78, 61, 8, 71, 34, 72}; int item; bool isFound; int location; char ch; cout << "Search the list (Y,y/N,n): "; cin >> ch; cout << endl; while (ch == 'Y' || ch == 'y') { cout << "Enter search item: "; cin >> item; cout << endl; isFound = false; location = recSequentialSearch(list,15,item); if (location != -1) cout << item << " found at position: " << location << endl; else cout << item << " not in the list" << endl; cout << "Search the list (Y/N): "; cin >> ch; cout << endl; } return 0; }
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