diff --git a/QSB/Utility/ListStack.cs b/QSB/Utility/ListStack.cs index bfc7b81d..89e133a2 100644 --- a/QSB/Utility/ListStack.cs +++ b/QSB/Utility/ListStack.cs @@ -6,7 +6,16 @@ namespace QSB.Utility; public class ListStack : IEnumerable { - private readonly List _items = new(); + private List _items = new(); + + public int Count => _items.Count; + + public ListStack() { } + + public ListStack(int capacity) + { + _items = new List(capacity); + } public void Clear() => _items.Clear(); @@ -33,6 +42,26 @@ public class ListStack : IEnumerable return default; } + public T RemoveFirstElementAndShift() + { + if (_items.Count == 0) + { + return default; + } + + var firstElement = _items[0]; + + if (_items.Count == 0) + { + return firstElement; + } + + // shift list left + _items = _items.GetRange(1, _items.Count - 1); + + return firstElement; + } + public T Peek() => _items.Count > 0 ? _items[_items.Count - 1] : default;