用于实现 UNDO 和 REDO 选项的数据结构 [英] data structure used to implement UNDO and REDO option
问题描述
我想实现 UNDO 和 REDO 选项(正如我们在 MS word 等中看到的).你能给我推荐一个数据结构吗,我该如何实现它.?
I want to implement UNDO and REDO option(as we see in MS word etc). Can you suggest me a data structure for it, and how can i implement it.?
推荐答案
它不是一种数据结构,而是一种设计模式.您正在寻找命令模式.
It isn't a data structure but a design pattern. You're looking for the Command Pattern.
标准是将Command对象保持在一个堆栈中以支持多级撤消.为了支持重做,第二个堆栈会保存您已撤消的所有命令.因此,当您弹出撤消堆栈以撤消命令时,您将弹出的命令推送到重做堆栈中.当你重做一个命令时,你反过来做同样的事情.您弹出重做堆栈并将弹出的命令推回撤消堆栈.
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. You do the same thing in reverse when you redo a command. You pop the redo stack and push the popped command back into the undo stack.
这篇关于用于实现 UNDO 和 REDO 选项的数据结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!