Return to site

Program For Evaluating Postfix Expression Using Stack In Java

broken image

Program For Evaluating Postfix Expression Using Stack In Java

java program to evaluate postfix expression using stack

The code inside each if is identical except for the result so, instead of the above, why not create a result() method; maybe something like: private static int result(char operator, int i1, int i2) {.. Just a question: Does the assignment includes writing a stack or is it ok to use the Java Stack implementation ()?? He wasn't clear with that, so I just wrote my own. 1

java program to evaluate postfix expression using stack

I was trying to figure out if it was possible to do the evaluation with a 'char' stack, but I didn't see that working out since as far as I'm aware a char can only handle one character at a time - i. HERE

Your popAsDigit() method is much better If I remember correctly, that is an exercise from the, which specifically uses one-digit numbers.. Pushing the int 16 back onto the stack will allow you to pop 16 later, still as an int. https://simpnusbundter.storeinfo.jp/posts/15764833

As for built-in classes, the best stack is, believe it or not You can probably push and pop those values as ints.. Have a thunk about it Hm, no thoughts at all? You could make all your if else's a switch statement.. I leave you to work out the details Have you thought about how to handle negative numbers? Is that '-1 2' or '1 -2', and how do you work it out? Just a few from the top of my head.. Those 48 and 57 magic numbers are error-prone This is where I'm uncomfortable Program To Evaluate Postfix ExpressionI really didn't want to write the method this way, but at the time I had no idea how to handle it. 0041d406d9 Click

It's not partly, it's entirely due to it Chars are not digits, and will never treat them as such. HERE