I have a problem here, I wanted to do a recursive linear search using vector and iterators, here's the code:
long int busca_sr(std::vector<long int> &amostra, const long int &key){
auto first = amostra.begin();
auto last = amostra.end();
if (last == first-1){
return -1;
}
else if(*last == key){
return 1;
}
else{
--last;
std::vector <long int> auxi1 (first, last);
return busca_sr(auxi1, key);
}
The problem is that when I run this function my pc hangs, I suspect the error is in the stop condition of my recursion, because when last is equal to first the auxiliary vector la will not be allocated, wanted a way to enter a stop condition without having to change the signature of the function, thanks!