Question: public static int p(char op) { switch(op) { case'*': case '/' : return 2; case '+': case '-': return 1; default: return -1; } }

 public static int p(char op) { switch(op) { case'*': case '/'

public static int p(char op) { switch(op) { case'*': case '/' : return 2; case '+': case '-': return 1; default: return -1; } } /** * Solves a postfix arithmetic expression. * @param postfix postfix expression to solve, ex. "3 4 2 + + 8 -" * @return integer solution, ex. 3 */ public static int solve(String postfix) { integers string: Input: postfix string Start with an empty stack of Start with a 0 result for each character c in postfix if c is a digit: push conto stack else: (c must be an op) Y = pop stack x = pop stack add x op y to result is top of stack Output: result result */ int result = 0; return result; } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!