#pragma once
#include <list>
#include <string>
#define LIST_SIZE 5
usingnamespace std;
int Search(list<string> & myList, list<string>::iterator & iterator, string value)
{
//base case, if we reach the end of the list
if (iterator == myList.end())
{
if (*iterator == value)
return distance(myList.begin(), iterator);
elsethrow"The value you searched for was not found";
}// other case, if search is correct
elseif (*iterator == value)
{
return distance(myList.begin(), iterator);
}//recursively repeat the process until differnt condition is satisfied
else
{
++iterator;
Search(myList, iterator, value);
}
}
When you try to search for something it can actually find, it prints a very odd value (typically in the range of 1.5million) and if you try to search for something that isn't in the list, it crashes, saying usually that the iterator is not dereferencable, among other errors.
Please help me out with this, see if there's anything outstanding that requires some attention. Things like the fact that I'm using list and recursion are required by the teacher for this assignment so they're not going to change.