0

Recursion

To use information from the last operation, I have to use recursion , but I don’t understand how to. I’m trying to modify a nested array, I have to change an element , but don’t want to have to do something like “arr[0][0][0][0].changeValue()”

1st Nov 2019, 6:26 PM
Jamie Charles
3 Respuestas
+ 4
That is not how recursion works. Recursion is used when you have a big problem and the solution to it is a smaller problem and this goes on. For eg take the factorial problem, to find 5's factorial you need a 4's factorial and to find a 4's factorial you need a 3's factorial and so on. So I don't think you can use it in your code for nested arrays.
1st Nov 2019, 7:29 PM
Avinesh
Avinesh - avatar
+ 3
Can you give little more detail about what your recursive function need to do ? If your purpose is to use previous information, then probably there is no need of recursion but if you still want then you can make function with arguments as array(unmodified), index value of element you want to change & new value with return type as array(return modified array & then use it as unmodified array in next call).
2nd Nov 2019, 1:08 AM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 1
i actually figured out what i was suppose to do and is similar to what you suggested!
2nd Nov 2019, 1:10 AM
Jamie Charles