I have the following iterative function:
int getNumPastasColididas(int i){
int c = 0;
for(int i = 0; i < size; i++)
c += table[i].hasColided;
return c; // c = 89832
}
I tried to reproduce the operation using a recursive code but when I make the call passing 0 as a parameter it does not work, returning 1.
int getNumPastasColididas(int i){
return (i < size) ?: table[i].hasColided + getNumPastasColididas(i + 1);
}
Why the recursive code does not reproduce the iterative result? Where is the error?