Skip to content

Instantly share code, notes, and snippets.

@DV8FromTheWorld
Created February 12, 2015 19:22
Show Gist options
  • Select an option

  • Save DV8FromTheWorld/80fb4409f95d8f4ffd4b to your computer and use it in GitHub Desktop.

Select an option

Save DV8FromTheWorld/80fb4409f95d8f4ffd4b to your computer and use it in GitHub Desktop.
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