RPN Question in Review

RPN:

    Consider the following arithmetic expression:
          3*5^(4-2)+6
       
  1. Use the method from class to translate this expression to RPN. (Do it step-by-step, using the stack and showing steps.)

    Operands are shifted to output. So ... shift 3, stack *, shift 5, stack ^ (stack higher prec), stack (, shift 4, stack -, shift 2, pop - and output it, destroy (), pop ^ and output it, pop * and output it, stack +, shift 6, pop + and output it. Done! The final answer is

          3542-^*6+
       
  2. Use the method from class to evaluate the resulting RPN. (Again do it step-by-step, showing the use of a stack.)

    Push 3, 5, 4, 2; pop 2 and 4, push 4-2 = 2; pop 2 and 5, push 5^(2) = 25; pop 25 and 3, push 75; push 6; pop 6 and 75, push 75+6 = 81.