mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-02-21 00:39:53 +00:00
Update ListStack.cs
This commit is contained in:
parent
20fe2c4fe7
commit
83a35d833f
@ -6,7 +6,16 @@ namespace QSB.Utility;
|
||||
|
||||
public class ListStack<T> : IEnumerable<T>
|
||||
{
|
||||
private readonly List<T> _items = new();
|
||||
private List<T> _items = new();
|
||||
|
||||
public int Count => _items.Count;
|
||||
|
||||
public ListStack() { }
|
||||
|
||||
public ListStack(int capacity)
|
||||
{
|
||||
_items = new List<T>(capacity);
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
=> _items.Clear();
|
||||
@ -33,6 +42,26 @@ public class ListStack<T> : IEnumerable<T>
|
||||
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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user