Undo/Redo implementation

后端 未结 10 1377
醉酒成梦
醉酒成梦 2020-11-28 18:59

Give me some thoughts how to implement undo/redo functionality - like we have in text editors. What algorithms should I use and what I may read. thanks.

10条回答
  •  爱一瞬间的悲伤
    2020-11-28 19:15

    My only two cents is that you would want to use two stacks to keep track of the operations. Every time the user performs some operations, your program should put those operations on a "performed" stack. When user want to undo those operations, simply pop operations from the "performed" stack to a "recall" stack. When user wants to redo those operations, pop items from "recall" stack and push them back to "performed" stack.

    Hope it helps.

提交回复
热议问题