Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- class Fixed_Stack<T>
- {
- public Fixed_Stack(UInt32 capacity)
- {
- _container = new List<T>();
- _capacity = capacity;
- }
- public void Push(T item)
- {
- _container.Add(item);
- if (_container.Count > _capacity)
- {
- _container.RemoveAt(0);
- }
- }
- public bool Any()
- {
- return _container.Count > 0;
- }
- public T Pop()
- {
- if (!Any())
- {
- throw new InvalidOperationException("The Stack is empty.");
- }
- T item = _container[_container.Count - 1];
- _container.RemoveAt(_container.Count - 1);
- return item;
- }
- private List<T> _container;
- private UInt32 _capacity;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement