ser*_*hio 5 .net collections design-patterns
实现Memento模式时的最佳效果(撤消/重做)
在巫婆收藏保持纪念品?
基本上,我需要这个(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
Run Code Online (Sandbox Code Playgroud)
变种:
最后我用了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
Run Code Online (Sandbox Code Playgroud)