I am trying to find the maximum value in a vector using recursion but I keep on getting a segmentation fault. I can't figure out the issue. Does anyone know why?
int find_max(vector<int> integer_array, int i) { //variable i just keeps track of the index starting at 0
if(i == integer_array.size()-1) {
return integer_array[i];
}
return max(integer_array[i], find_max(integer_array, i++));
}
//Example of a call: find_max(vector_array, 0);
UPDATE: I know it's inefficient but this is just for practicing recursion...
i++isi. Changei++toi + 1.