.net - 使用 Memento : Stack, 队列或仅使用 LinkedList 撤消/重做?

标签 .net design-patterns collections

实现时最好有什么Memento pattern (用于撤消/重做)

在女巫收藏中保留纪念品?

基本上,我需要这个(c = 更改,u = 撤销,r = 重做):

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

变体:
  • 链表 - 原则上可能,可能没有优化。
  • 队列 - 不适用于此任务,IMO。
  • 堆栈 - 不适用于撤消和重做;
  • 双栈 - 也许是最优的,但无法控制撤销的最大大小。
  • 最佳答案

    最后,我使用了 LinkedList

    Public Sub Add(ByVal item As T)
      If _list.Count > 0 Then
        If Me.IsFull Then
          ' we forgot (delete) the oldest state '
          _list.RemoveFirst()
        End If
        ' remove all the following the current items objects '
        Dim lastNode As LinkedListNode(Of T) = _list.Last
        While Not Object.ReferenceEquals(_currentNode, lastNode)
          _list.RemoveLast()
          lastNode = _list.Last
        End While
      End If
    
      ' add the new item and point current to it '
      _currentNode = _list.AddLast(item)
    End Sub
    

    关于.net - 使用 Memento : Stack, 队列或仅使用 LinkedList 撤消/重做?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2333416/

    相关文章:

    c# - 生成具有不同 'Content' 的单选按钮

    javascript - 将实例方法也用作静态方法是个好习惯吗?

    java - 多态性的有效使用?

    c# - C# 中是否有非唯一键排序列表泛型集合?

    java - 对 ArrayList 使用可选索引 - 可能吗?

    c# - Win8 Metro 风格应用程序中的 OpenID(使用 Steam 进行身份验证)

    c# - 传递给 WCF 服务的可选查询字符串参数

    .net - 在.NET中调试调用的功能

    PHP 设计模式 : Multiple websites inside one script

    java - 迭代器没有无需移动光标即可直接获取NextElement的方法