Skip to content

Instantly share code, notes, and snippets.

@neilcampbell
Created May 4, 2015 04:07
Show Gist options
  • Save neilcampbell/df548e8ef81888296e25 to your computer and use it in GitHub Desktop.
Save neilcampbell/df548e8ef81888296e25 to your computer and use it in GitHub Desktop.
C# DropOutStack
public class DropOutStack<T> : LinkedList<T>
{
private readonly int _capacity;
public DropOutStack(int capacity)
{
_capacity = capacity;
}
public void Push(T item)
{
if (this.Count() >= _capacity)
{
RemoveLast();
}
AddFirst(item);
}
public T Pop()
{
if (!this.Any())
{
throw new InvalidOperationException("Stack empty.");
}
var item = First;
RemoveFirst();
return item.Value;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment