Reputation: 87
i want to create a minimax tree which has 9 depth. I used 9 nested loop and too many variable. Now i want to convert this loops to recursive. Thank you for answers. This my code.
int a,b,c,d,e,f,g,h;
for(a=0;a<9;a++)
{
y=y->branch[a];
yap(y,8);
for(b=0;b<8;b++)
{
y=y->branch[b];
yap(y,7);
for(c=0;c<7;c++)
{
y=y->branch[c];
yap(y,6);
for(d=0;d<6;d++)
{
y=y->branch[d];
yap(y,5);
for(e=0;e<5;e++)
{
y=y->branch[e];
yap(y,4);
for(f=0;f<4;f++)
{
y=y->branch[f];
yap(y,3);
for(g=0;g<3;g++)
{
y=y->branch[g];
yap(y,2);
for(h=0;h<2;h++)
{
y=y->brancg[h];
yap(y,1);
}
}
}
}
}
}
}
}
Upvotes: 2
Views: 1814
Reputation: 493
void recursive(int max)
{
int a;
for(a=0;a<max;a++)
{
y=y->branch[a];
yap(y,max - 1);
if (max > 2)
recursive(max - 1);
}
}
Upvotes: 1