Last active
June 14, 2017 20:14
-
-
Save Dkowald/5e6c53d058a02fb4ee5a972e63c3b933 to your computer and use it in GitHub Desktop.
Simple length-limited stack
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| namespace kwd.gist { | |
| using System.Collections.Generic; | |
| public class CircularStack<T> | |
| { | |
| private readonly int _max; | |
| private readonly List<T> _items = new List<T>(); | |
| public CircularStack(int max) | |
| { | |
| _max = max; | |
| } | |
| public void Push(T newItem) | |
| { | |
| _items.Insert(0, newItem); | |
| if(_items.Count >= _max){ _items.RemoveAt(_items.Count-1);} | |
| } | |
| public IReadOnlyList<T> Items => _items; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment