Created
February 12, 2015 19:22
-
-
Save DV8FromTheWorld/80fb4409f95d8f4ffd4b to your computer and use it in GitHub Desktop.
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
| using UnityEngine; | |
| using System.Collections; | |
| using System.Collections.Generic; | |
| using System.Linq; | |
| public class LimitedStack<T> | |
| { | |
| private LinkedList<T> stack; | |
| private int maxSize; | |
| public LimitedStack(int maxSize) | |
| { | |
| stack = new LinkedList<T>(); | |
| this.maxSize = maxSize; | |
| } | |
| public void Clear() | |
| { | |
| stack.Clear(); | |
| } | |
| public void Push(T entry) | |
| { | |
| stack.AddFirst(entry); | |
| if (stack.Count > maxSize) | |
| { | |
| stack.RemoveLast(); | |
| } | |
| } | |
| public T[] ToArray() | |
| { | |
| return stack.ToArray(); | |
| } | |
| public int GetCount() | |
| { | |
| return stack.Count; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment