What you are looking for is called a dropdown stack . AFAIK, BCL does not contain one, although they are trivial to implement. As a rule, the functionality of Undo and Redo is based on such data structures.
They are basically an array, and when you click on the stack, the "top" of the stack moves around the array. In the end, the top will return to the beginning when the stack is full and replace the "bottom" stack.
Google did not provide much information about this. This is the best I could find:
(Warning PDF) http://courses.cs.vt.edu/~cs2704/spring04/projects/DropOutStack.pdf
Here is the boiler plate code to get you started. I will let you fill in the rest (health check, count, indexer, etc.).
class DropOutStack<T> { private T[] items; private int top = 0; public DropOutStack(int capacity) { items = new T[capacity]; } public void Push(T item) { items[top] = item; top = (top + 1) % items.Length; } public T Pop() { top = (items.Length + top - 1) % items.Length; return items[top]; } }
source share