Last active
September 24, 2019 07:53
-
-
Save Mirch/88e0d11c8c5db258fd0b191311f004ce to your computer and use it in GitHub Desktop.
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 interface IStack | |
{ | |
void Push(StackNode node); | |
StackNode Pop(); | |
} | |
public class Stack : IStack | |
{ | |
private LinkedList<StackNode> _elements; | |
public Stack() | |
{ | |
_elements = new LinkedList<StackNode>(); | |
} | |
public StackNode Pop() | |
{ | |
if (_elements.Count == 0) | |
{ | |
return null; | |
} | |
var last = _elements.Last.Value; | |
_elements.RemoveLast(); | |
return last; | |
} | |
public void Push(StackNode node) | |
{ | |
_elements.AddLast(node); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment