Evaluating a postfix expression with a stack

A program evaluates the postfix (reverse Polish) expression below by reading tokens from left to right with an initially empty stack. Each number is pushed. Each binary operator pops two values, applies the operator to them, and pushes the result. Division here is exact, with no rounding.


9314+−∗2/9 \quad 3 \quad 1 \quad 4 \quad + \quad - \quad * \quad 2 \quad /


Give the final value left on the stack, as an integer, and the maximum number of elements the stack holds at any moment during the evaluation, as an integer.

Your answers

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More Stacks Questions: