My question is: why does the recursive method recognize index[0] as a value to compare?
i.e. in the in the array:
int [] numbers2 = {9, 1, 7, 3, 5, 6};
9 is returned as the largest, but in the Math.max below it compares the index++ to the recursive method. Why doesn't this skip index 0?
...
public static int largestArrayItem(int [] numbers)
{
return largestArrayItemAuxiliary(numbers, 0);
}
private static int largestArrayItemAuxiliary(int [] numbers, int index)
{
if (index == numbers.length - 1)
{
return numbers[index];
}
else
{
return Math.max(numbers[index++], largestArrayItemAuxiliary(numbers, index++));
}
}
This might be a trivial question, but I understand how recursion works in say, the basic factorial example, but this is beyond my first-year grasp.
Any/all help is appreciated.
thanks!

New Topic/Question
Reply


MultiQuote



|