CJCoding With Joseph
15free / daySign inCreate account

Evaluate a Postfix Expression

In postfix notation the operator comes after its two operands, so 3 4 + means 3 + 4. A stack evaluates it in one pass. The Deque, the split into tokens, the loop and isOperator() are already written.

Requirements:
1. For a number token, push its int value onto the stack.
2. For an operator token, pop two values and push the result of +, -, * or / on them. The first pop is the right operand and the second pop is the left one, which matters for - and /.
3. Use integer division for /, and return the single value left on the stack, or -1 if there is none.

Do NOT write a main method.

Expected Output:

7
14
5
7

= newline. The output ends with a newline — print one after the last line.

Hints4 available
Topics:
Data Structures & AlgorithmsStacks
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (sysout, psvm, fori)

Your Output

Run your code to see the output here...

Test Cases

Run your code to see test case results.