index
всегда 0
. Вы должны передать его как параметр и проверить, иначе он не закончится.
bool areEqual(int *A1, int size1, int *A2, int size2, int index=0)
{
if (size1 != size2) return false;
if (index == size1) return true;
if (A1[index] != A2[index]) return false;
return areEqual(A1, size1, A2, size2, index+1);
}
Вы можете разделить его на 2 функции, что более понятно.
bool areEqualRecursive(const int *A1, const int *A2, const int size, int index){
if (index == size) return true;
if (A1[index] != A2[index]) return false;
return areEqualRecursive(A1, A2, size, index+1);
}
bool areEqual(const int *A1, const int size1, const int *A2, const int size2){
if(size1 != size2) return false;
if(A1 == A2) return true;
return areEqualRecursive(A1, A2, size1, 0);
}
Вызов оба случая:
bool is_equal = areEqual(arr1, size1, arr2, size2);