Solved
Removing Recursion
Posted on 1997-09-30
Hi
When I need remove recursion from proc like :
Void P()
{
if (Expression(x))
{
A(x)
P()
B(x)
}else C(x)
}
where x is global variables and A,B,C if functions on them.
Then I have this proc as result :
int N=0;
void P()
{
while (Expression(x))
{
A(X)
N++
}
C(x);while (N--!=0) B(x);
}
When I need remove recursion from proc like :
Void P()
{
if (Expression(x))
{
A(x)
P()
B(x)
P()
C(X)
}else D(x)
}
Then I have this proc as result :
int N=1;
void P()
{
do
{ while (Expression(x)) { A(x); N*=2; }
D(x);
while ((N!=1) && (N%2)) { N=N/2;C(x); }
if (N==1) goto koniec;
N=N+1;
B(x);
} while (N!=1);
}
But i Have proc with 3 calls :
Void P()
{
if (Expression(x))
{
A(x)
P()
B(x)
P()
C(X)
P()
D(x)
}else E(x)
}
I can't remove the Recursion. Mayby You can ?
I understand remove recursion in example 1 but not in example 2.
1).I give points with grade B in exchange for solution of example3.
2). I give points with grade A in exchange of description how Example2 was created.
3).I give all my points (at 30.iX i have 267pt) with grade A in exchange of Point1 and 2 of My Question.