Это мой тестовый массивFinding Наибольшее значение в массиве, используя рекурсию
int [] A = {1,2,7,3,5,6};
это метод
public static int largest(int [] A)
{
int temp = A[0];
return largestRec(A, 0, A.length - 1, temp);
}
// WRITE THIS METHOD that returns the largest of the elements in A
// that are indexed from low to high. RECURSIVELY!
private static int largestRec(int [] A, int low, int high, int temp)
{
if (low == high)
return A[low];
if (low <= A.length){
if (A[low] > temp){
temp = A[low];
}
largestRec(A, low+1, high, temp);
}
return temp
}
Почему возвращаются в исходное состояние TEM и возвращения A[0]
которое 1
?
Спасибо, что решите все. – user3247435