I am new here and I am somehow stuck. I created an recursive algorithm that uses an global variable for remembering the Position he made the recursive call and I am trying to get rid of this variable as for me it seems to be not a good solution.
Is there any chance to get rid of this global variable? I cannot adjust the method-head so therefore the Interface of the method is fixed.
Here you can see my Code:
static int pos = -1;
static boolean writeInfix(char[] expr) {
boolean result;
pos++;
int printpos = pos;
if(expr[pos]=='+'||expr[pos]=='-'||expr[pos]=='/'||expr[pos]=='*'){
System.out.print("(");
writeInfix(expr);
System.out.print(expr[printpos]);
result = writeInfix(expr);
System.out.print(")");
return result;
}else if(expr[pos] >= 'a' && expr[pos] <= 'z'){
System.out.print(expr[pos]);
return true;
}else{
return false;
}
}
Thank you for your help :)