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:
Starting from an empty document with both stacks empty, the user performs this sequence: type a, type b, type c, undo, undo, type d, undo, redo, redo.
After the whole sequence, give the number of elements in the undo stack and in the redo stack as whole numbers, the single character at the top of the undo stack, and the full text of the document.
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.
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.
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.