algorithm - Best way to write a recursive function in C++? -


Question
I want to know that one of the variables to implement the depth recycling Viable method so that I can run a function in each stage and I will be able to do any better / other solution for the description problem.
Description
Suppose I want to do an action that fills an array in patterns
x, y, x, y, x, y Where x and y are variables defined by some algorithms and x, y, z, x, y, z where x, y and z are variables defined by the same algorithm I

all of this The variables must continue. Is this a viable way of implementing it?

  zero recurse_n (int n) {while (n> gt; 0) {--n; Recurse_n (n); N = 0; // algorithm use}}  

Edit: The last REDA type was deleted the last time. Brainfart.

So, depending on your comment, you want to know the best way to set up a recurring function . The work you have done will work, but it is complex and a little confusing. What do I do to simplify:

  zero recurse_n (int n) {if (n & lt; = 0) {// break-out status return; } -n; Recurse_n (n); // Your algorithm stuff is here}  

It will be easy to see what's going on. One thing I will add is that you want to do algorithm stuff before calling recurse_n, but it all depends on your algorithm.

If you think about it, the way I have written it, it will recres until the n is equal to or equal to 0 before doing any of the algorithms. It may happen that you want to work in algorithms, then residue again.


Comments