I want to write a recursive function that creates all possible solutions to the problem. I thought I needed to pass an array, and then at each recursive step set it to all possible values ββin this recursive step, but then I started to wonder if this is possible, since C passes the array by passing a pointer. How do you usually deal with this?
I think about this. The array will take different values ββdepending on the selected path. Actually we would like to pass an array by value, I think.
recFunc(int* array, int recursiveStep) {
for (int i = 0; i < a; i++) {
if (stopCondition) {
doSomething;
}
else if (condition) {
array[recursiveStep] = i;
recFunc(array, recursiveStep+1);
}
}
}
source
share