Question: Type or paste question here Two stacks: Problem 4 (15 points) For the expression 1-6* 2 + 7 = (12-14 * 3)) + 8 trace
Type or paste question here
Two stacks: Problem 4 (15 points) For the expression 1-6* 2 + 7 = (12-14 * 3)) + 8 trace the following algorithm and show the content of stacks after any push and pop operation. Keep in mind operators has lower precedence than +/- and has precedence over +/- Algorithm EvalExpo opStk holds operators Input a stream of tokens representing on arithmetic expression (with numbers) valStk holds values Output the value of the expression Use $ as special "end of Input" token with lowest precedence Algorithm dopo while there's another token z xvalStk popo If IsNumber(z) then ye-valStk. popo: valStk.push(z) op-opStkpop valStk. push yopx) repeatOps(2) Algorithm repeatOpsrefOp ): opStk.push(z) while (valStk.size() > 1A repeatOps($); prec(refop) return valStk.top precopStk.top() doop olse
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
