Question: Can someone complete this algorithm in java8? 1. Evaluating Postfix Notation (40 points) Sketch of algorithm for evaluating postfix strings: Rules: - Create stack s.
Can someone complete this algorithm in java8?
1. Evaluating Postfix Notation (40 points) Sketch of algorithm for evaluating postfix strings:
Rules: - Create stack s.
- For each token, x, in the postfix expression: 1 If x is T or F push it into the stack s. 2 Else if x is a unary operator i pop an operand, op1, from s ii compute x op1 (see unary table below) iii push the result into s 3 Else if x is a binary operator i pop an operand, op2, from s ii pop an operand, op1, from s iii compute op1 op2 x iv push the result into s
- If you do not have enough operands in s to perform an operation you should throw an exception.
- Likewise, if s contains more than one operand after all of the tokens are evaluated you should throw an exception.
- Otherwise pop and return the only value in s.
Operator Type Usage Calculation
unary operator op1 NOT !op1
binary operator op1 op2 AND op1 && op2
binary operator op1 op2 NAND !(op1 && op2)
binary operator op1 op2 OR op1 || op2
binary operator op1 op2 NOR !(op1 || op2)
binary operator op1 op2 XOR op1 ! = op2
binary operator op1 op2 COND !op1 || op2
binary operator op1 op2 BICOND op1 == op2
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
