- How does undo work in stack?
- Does undo use stack?
- Which data structure is most suited to implement the undo feature?
- Which data structure you will choose to implement undo redo in a text editor why and how?
How does undo work in stack?
If “WRITE” string is encountered, push the character to Undo stack. If “UNDO” string is encountered, pop the top element from Undo stack and push it to Redo stack. If “REDO” string is encountered, pop the top element of Redo stack and push it into the Undo stack.
Does undo use stack?
The best way to look at undo/redo is two stacks of operations the user has performed: The Undo stack is the "history" of what they've done. The redo stack is the breadcrumbs back to the initial state before they started undoing.
Which data structure is most suited to implement the undo feature?
Which data structure is used in redo-undo feature? Explanation: Stack data structure is most suitable to implement redo-undo feature.
Which data structure you will choose to implement undo redo in a text editor why and how?
You're looking for the Command Pattern. The standard is to keep the Command objects in a stack to support multi level undo. In order to support redo, a second stack keeps all the commands you've Undone. So when you pop the undo stack to undo a command, you push the same command you popped into the redo stack.