39 lines
No EOL
695 B
C#
39 lines
No EOL
695 B
C#
namespace KumiScript.Reader
|
|
{
|
|
|
|
public class Stack<T>
|
|
{
|
|
List<T> _values;
|
|
|
|
public Stack(int size)
|
|
{
|
|
_values = new List<T>(size);
|
|
}
|
|
|
|
public T Pop()
|
|
{
|
|
if (!_values.Any())
|
|
throw new Exception("Stack empty!");
|
|
|
|
T last = _values.Last();
|
|
_values.Remove(last);
|
|
return last;
|
|
}
|
|
|
|
public bool Push(T item)
|
|
{
|
|
_values.Add(item);
|
|
return true;
|
|
}
|
|
|
|
public bool IsEmpty()
|
|
{
|
|
return !_values.Any();
|
|
}
|
|
|
|
public List<T> ToList()
|
|
{
|
|
return _values;
|
|
}
|
|
}
|
|
} |