the following algorithm is obviously faulty.
Examining even the simplest case (calling a(1,2); )shows the problem. I know it can be 'worked around' by
a(1,n+1) if u need n ints in displayed in preorder, but I don't like such work-arounds.
How should I change the stopping condition, or is it that I need another variable.... I bet it's simple but I don't see it
thank you for your help!
Avendeval
Code:
void a(int r, int s){
int x = (s+r)/2;
if(r==s)
return;
cerr << x <<" ";
a(r, x,);
a(x+1, s);
}
Examining even the simplest case (calling a(1,2); )shows the problem. I know it can be 'worked around' by
a(1,n+1) if u need n ints in displayed in preorder, but I don't like such work-arounds.
How should I change the stopping condition, or is it that I need another variable.... I bet it's simple but I don't see it
thank you for your help!
Avendeval