Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections.Generic;
- namespace TodoApplication
- {
- public class LimitedSizeStack<T>
- {
- private readonly LinkedList<T> stackFromList = new LinkedList<T>();
- private readonly int limitOfStack;
- public LimitedSizeStack(int limit)
- {
- limitOfStack = limit;
- }
- public void Push(T item)
- {
- if(limitOfStack != 0)
- {
- if(stackFromList.Count >= limitOfStack)
- {
- stackFromList.RemoveFirst();
- }
- stackFromList.AddLast(item);
- }
- }
- public T Pop()
- {
- var deepestValue = stackFromList.Last;
- stackFromList.RemoveLast();
- return deepestValue.Value;
- }
- public int Count
- {
- get
- {
- return stackFromList.Count;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement