I have an algorithm that seems to crash C++ due to the recursion depth. I don't know how to change my algorithm (if I could, I would) and I don't want to post it here because it pertains to an online game, but my question is how to increase the recursion depth in something like devcpp+? Thanks!
Or if someone happens to know an easy answer to this:
I am using recursion because each layer involves a loop. The alternative, in my mind, to using recursion would be to use ungodly levels of nested for loops to get all possible combinations of values.
There is no such thing as 'recursion depth settings'. Most likely you're getting a stack overflow because recursion is rather stack-heavy. Even so, the problem is most likely something of this nature:
1 2 3 4 5
void myRecursion() {
int myInts[LARGE_NUMBER];
// code
myRecursion();
}
Lesson of the day: recursion = memory management.
If that's not the error you're getting, you'll probably need to provide more information.
Yeah, the numbers involved (on the order of 9000 or so, where it basically searches for all possible sub-groupings) are quite big. I can get the program to run by arbitrarily shortening the loop inside the function but then my output is slightly off.
I've stripped out the stuff that doesn't matter (each line is different but I'll only point to the actual calls) but it looks something along these lines:
By any chance do function(conditionN) stay constant for certain cases? If so, you could reduce the recursion calls by saving the results of some of them.
It doesn't repeat forever. It works perfectly fine for smaller initial n's. It just breaks when n is too large.
To be more specific, in the loop, I go from 1 to n. I have two variables, x and y, which equal n. x gets passed into some conditions while y is passed into others, so I'm basically splitting everything up every which way. I also exit the loop early if I find that var > bestvar.
Then you'll probably have to turn to Moschops' suggestion of increasing the stack size. Do mind that this will cause problems if you have to send your code to someone else, since his stack size might have a lower limit.