Undo/Redo using Memento: Stack, Queue or just LinkedList?

Posted by serhio on Stack Overflow See other posts from Stack Overflow or by serhio
Published on 2010-02-25T10:58:19Z Indexed on 2010/05/03 19:58 UTC
Read the original article Hit count: 245

Filed under:
|
|

What is the best having when implementing Memento pattern (for Undo/Redo)

in witch collection to Keep Mementos?

Basically, I need this(c = change, u = undo, r = redo):

                  0
                  *c
            -1    0
                  *c
      -2    -1    0
                  *c
-3    -2    -1    0
                  <u
      -2    -1    0    1
                  *c
-3    -2    -1    0

Variants:

  • LinkedList - possible in principle, maybe not optimized.
  • Queue - not adapted for this task, IMO.
  • Stack - not adapted for undo AND redo;
  • Double Stack - maybe optimal, but can't control the undo maximum size.

© Stack Overflow or respective owner

Related posts about .NET

Related posts about design-patterns