Open
Description
Hi,
One criterion is missing before the 68th row, at the while loop premise. Instead of
while (!operatorStack.isEmpty() && (operatorStack.peek() == '*' || operatorStack.peek() == '/' || operatorStack.peek() == '%' )) { processAnOperator(operandStack, operatorStack); }
the correct version would be:
while(!operatorStack.isEmpty() && (operatorStack.peek() == '*' || operatorStack.peek() == '/' || operatorStack.peek() == '^' || operatorStack.peek() == '%')) { processAnOperator(operandStack, operatorStack); }
Without this criterion (operatorStack.peek() == '^' ||) the following expression gives wrong result:
(5 * 2 ^ 3 * 2 + 2 * 3 % 2) * 4 is correctly 320, but without this criterion it is 1280, because 2 ^ 3 * 2 is evaluated as 2 ^ 6.
Metadata
Metadata
Assignees
Labels
No labels