Recursion Revisited again, and again!
This is just so frustrating for me. I finished the chapter on recursion and thought, wrongly, that I was finished with recursion. Well, I am not. I am rewriting a sequential seach function of an array-based list class as an ADT. I understand that I have to find the base case(s), and taking the original function and calling it again with a smaller range of elements from the list. I think I have successfully done that with what I have written, but won't know until I can find the final piece which is making the list smaller.
The class has private members of a list pointer (elem Type *list), length and maxSize. The function accepts a reference to item as its argument. So, that is all I can include in the recursive call to the function, so HOW do I get the list one element smaller in the recursive call??? Recursion will be the death of me in programming.
My code is:
Thanks for the help.
template <class elemType>
int arrayListType<elemType>::seqSearch(const elemType& item)
if (length == 0 || loc == length)
else if (list[loc] == item)
return seqSearch(item); //THIS IS MY PROBLEM STATEMENT - MENTAL BLOCK!!!
} //end seqSearch