What is Undo / Redo Stack?
Two stacks remember the past and the undone future of an editor.
Type a tool name, format or task
Two stacks remember the past and the undone future of an editor. Interactive step-by-step animation with JavaScript code, complexity and front-end use cases.
Loading animation...
Two stacks remember the past and the undone future of an editor. Before every change, push the current state on the undo stack. Undo pops the undo stack and pushes the current state on the redo stack. Redo does the reverse. A new change clears the redo stack. Time complexity: O(1) per action. Space complexity: O(history). Text editors, drawing tools, form builders and any UI that supports Ctrl+Z.
Two stacks remember the past and the undone future of an editor.
Time: O(1) per action. Space: O(history).
Text editors, drawing tools, form builders and any UI that supports Ctrl+Z.
No. This converter runs in your browser for ordinary use, so the input is not sent to a backend by this tool.
Keep working without searching again.
Undo/redo uses two stacks. The undo stack remembers earlier states; the redo stack remembers states you undid.
class History {constructor() { this.undoStack = []; this.redoStack = []; this.text = ""; }type(ch) {this.undoStack.push(this.text);this.text += ch;this.redoStack = [];}undo() {if (!this.undoStack.length) return;this.redoStack.push(this.text);this.text = this.undoStack.pop();}redo() {if (!this.redoStack.length) return;this.undoStack.push(this.text);this.text = this.redoStack.pop();}}
Tip: use the arrow keys to step and the space bar to play or pause.