7
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 play the function using recursive code but when I make the call passing 0 as parameter it does not work, returning 1.
int getNumPastasColididas(int i){
return (i < size) ?: table[i].hasColided + getNumPastasColididas(i + 1);
}
Why does recursive code not reproduce the iterative output? Where is the error?
Put the whole function to make it easy for us.
– Bacco
The answer helped you?
– durtto
Did any of the answers below solve your problem? Do you think you can accept one of them? Check out the [tour] how to do this, if you still don’t know how to do it. This helps the community by identifying the best solution for you. You can only accept one of them, but you can vote for any question or answer you find useful on the entire site.
– Maniero