用于实施UNDO和REDO选项的数据结构 [英] data structure used to implement UNDO and REDO option

查看:198
本文介绍了用于实施UNDO和REDO选项的数据结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现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对象保留在堆栈中以支持多级撤销。为了支持重做,第二个堆栈保存所有的Undone命令。所以当你弹出撤消堆栈来撤消一个命令时,你把你弹出的命令推到重做堆栈中。当您重做命令时,您会做相同的事情。您弹出重做堆栈,将弹出的命令推回到撤消堆栈。

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆