Quantcast
Viewing latest article 3
Browse Latest Browse All 5

Answer by user1196549 for One of many recursive calls of a function found the correct result, but it can't "tell" the others. Is there a better fix than this ugly workaround?

You need to stack the indexes as you go, and assign the recursive function a success flag. When you perform a recursive call, you push the new index. When the function returns, in case of failure you pop and continue the search, and in case of success you do nothing but return success. In the end, the stack will be either empty or filled with the solution.

The stack can be a global variable or be passed as an argument.


Viewing latest article 3
Browse Latest Browse All 5

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>