Recursion | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
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 Respostas
+ 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