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.
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.
Unlock full course notes by signing up
Order in which call-stack frames are popped
When a function is called, a frame for it is pushed onto the program's call stack, and when the function returns, its frame is popped. Running main() in the Python program below pushes and pops several frames. Arrange the frames in the order in which they are popped from the call stack, first popped at the top.
Undo and redo with two stacks
A simple text editor implements undo and redo with two stacks. Every typing action appends one character to the end of the document and pushes that character onto the undo stack. The editor follows three rules:
A new typing action pushes onto the undo stack and empties the redo stack.
Undo pops the top of the undo stack, removes that character from the document, and pushes it onto the redo stack. Undo does nothing if the undo stack is empty.