Question: Need help with my function.. Suppose to convert a postfix expression to infix expression. 2 10 4 * 5 / + 9 3 - -
Need help with my function.. Suppose to convert a postfix expression to infix expression.
2 10 4 * 5 / + 9 3 - - or (cannont accept spaces) 2104*5/+93--
Is giving me: ((1+((0*4)/5))-(9-3))
should be ((2+((10*4)/5)-(9-3))
Where am I going wrong? Please add comments if you fix !
string Expression::postToIn(string myExpression){ stack
if (isOperand(myExpression[i])){ if(leftDone){ if(rightDone){ Stack.push(leftValue); leftValue = rightValue; rightValue = myExpression[i];
}else{ rightValue = myExpression[i]; rightDone = true; } }else{ leftDone = myExpression[i]; leftDone = true; }
}else{ if(rightDone){
leftValue = leftParenthesis + leftValue + myExpression[i] + rightValue + rightParenthesis; rightDone = false; } else{
rightValue = leftValue; leftValue = Stack.top(); Stack.pop(); leftValue = leftParenthesis + leftValue + myExpression[i] + rightValue + rightParenthesis; }
}
} return leftValue; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
