I need help with creating a recursive method that find the max value in a vector. The method should have the following signature:
public int max(int[] v)
And use a private helping method.
Here's the method that I'm trying to use:
private int biggest(int a, int b){
if(a > b){
return a;
}
else{
return b;
}
}
public int maxRecursive(int[] v){
if(v.length > 1){
return biggest(v[0], maxRecursive(Arrays.copyOfRange(v, 1, v.length - 1)));
}
else{
return v[0];
}
}
However, all this seem to do is return the middle value of a array. Ex: If the array is `{1,2,3,5,6,7,8} the method returns 5.