Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void Trim<T> (this Stack<T> stack, int trimCount)
- {
- if (stack.Count <= trimCount)
- return;
- stack = new
- Stack<T>
- (
- stack
- .ToArray()
- .Take(trimCount)
- );
- }
- 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];
- }
- }
Add Comment
Please, Sign In to add comment