Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exercise_20_23 #17

Open
csv77 opened this issue Jul 15, 2017 · 0 comments
Open

Exercise_20_23 #17

csv77 opened this issue Jul 15, 2017 · 0 comments

Comments

@csv77
Copy link

csv77 commented Jul 15, 2017

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant