Created
May 4, 2015 04:07
-
-
Save neilcampbell/df548e8ef81888296e25 to your computer and use it in GitHub Desktop.
C# DropOutStack
This file contains 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
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