Advertisement
Guest User

Untitled

a guest
Oct 10th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. public interface IStack
  2. {
  3. void Push(StackNode node);
  4. StackNode Pop();
  5. }
  6.  
  7. public class Stack : IStack
  8. {
  9. private LinkedList<StackNode> _elements;
  10.  
  11. public Stack()
  12. {
  13. _elements = new LinkedList<StackNode>();
  14. }
  15.  
  16. public StackNode Pop()
  17. {
  18. if (_elements.Count == 0)
  19. {
  20. return null;
  21. }
  22. var last = _elements.Last.Value;
  23. _elements.RemoveLast();
  24. return last;
  25. }
  26.  
  27. public void Push(StackNode node)
  28. {
  29. _elements.AddLast(node);
  30. }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement