Guest User

Untitled

a guest
May 23rd, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class Stack implements StackADT {
  4. private LinkedList<Object> stack;
  5.  
  6. Stack () {
  7. this.stack = new LinkedList<Object>();
  8. }
  9.  
  10. public boolean empty() {
  11. return (this.size() == 0);
  12. }
  13.  
  14. public int size() {
  15. return this.stack.size();
  16. }
  17.  
  18. public Object peek() throws EmptyStackException {
  19. if(!this.empty()) {
  20. return this.stack.getLast();
  21. } else {
  22. throw new EmptyStackException();
  23. }
  24. }
  25.  
  26. public Object pop() throws EmptyStackException {
  27. if(!this.empty()) {
  28. return this.stack.removeLast();
  29. } else {
  30. throw new EmptyStackException();
  31. }
  32. }
  33.  
  34. public void push(Object item) {
  35. this.stack.add(item);
  36. }
  37.  
  38.  
  39. }
Add Comment
Please, Sign In to add comment