I would like to make recursion in for loop with access to following iterators independently.
I tried to do that, but it looks like nested loop doesn't update its parent iterator. I am not sure what's wrong here:
std::vector<int> it;
// some code that fill "it" vector
std::vector<int *> iter;
for(int i=0; i<it.size(); i++)
{
iter.push_back(&it(i));
}
int sweek = 0;
int dup=0;
// And now call the function which definition is:
void matrixRecursion()
{
int start = sweek;
int end = matrix[sweek];
for(it(start); it(start)<end; it(start)++)
{
if(sweek < it.size()-1)
{
sweek++;
matrixRecursion();
}
else
{
for(int t=0; t<it.size(); t++)
{
dup += nIndex[*iter[t]];
}
}
}
}
std::vector<int> it;
// some code that fill "it" vector
std::vector<int *> iter;
for(int i=0; i<it.size(); i++)
{
iter.push_back(&it(i));
}
int sweek = 0;
int dup=0;
// And now call the function which definition is:
void matrixRecursion()
{
int start = sweek;
int end = matrix[sweek];
for(it(start); it(start)<end; it(start)++)
{
if(sweek < it.size()-1)
{
sweek++;
matrixRecursion();
}
else
{
for(int t=0; t<it.size(); t++)
{
dup += nIndex[*iter[t]];
}
}
}
}
To copy to clipboard, switch view to plain text mode
For example lets say `it.size()` is 3. Then if everything would work as I expect the result should be like that:
for(int i=0; i<matrix[0]; i++)
{
for(int j=0; j<matrix[1]; j++)
{
for(int k=0; k<matrix[2]; k++)
{
dup += nIndex[i] + nIndex[j] + nIndex[k];
}
}
}
for(int i=0; i<matrix[0]; i++)
{
for(int j=0; j<matrix[1]; j++)
{
for(int k=0; k<matrix[2]; k++)
{
dup += nIndex[i] + nIndex[j] + nIndex[k];
}
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks