I have recently created an elaborate Undo/Redo mechanism for a programm of mine. It is an editor that works with specific XML files. However, since certain changes may or may not change any amount of nodes in the XML file, I am currently backing up the whole XML document as a clone.
So far, I've been using two System.Collections.Generic.Stack(Of XmlNode)
objects to store them, and skipping back and forth works very well. But now I want to limit the number of steps one can undo, i. e. I need to throw out the oldest entries if the number of items in the undo stack exceeds a certain threshold.
How would I do that?
P.S.: It occured to me that I might use something like a Deque, so I already implemented my own DoubleEndedQueue(Of T)
. I could easily emulate a limited stack with that. It uses a System.Collections.Generic.List(Of T)
, though, and I don't know if List.Insert(item, 0)
is high-performance O(1) or O(n).