Advertisement
Guest User

Untitled

a guest
Oct 18th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package javaapplication3;
  7.  
  8. import java.util.ArrayList;
  9. import java.util.List;
  10.  
  11. /**
  12. *
  13. * @author student
  14. */
  15. public class MyStack {
  16. private List<Object> list = new ArrayList<Object>();
  17. public boolean isEmpty(){
  18. return list.isEmpty();
  19. }
  20. public int getSize(){
  21. return list.size();
  22. }
  23. public Object peek(){
  24. return (Object)list.get(list.size()-1);
  25. }
  26. public Object pop(){
  27. Object a = list.get(list.size()-1);
  28. list.remove(a);
  29. return a;
  30. }
  31.  
  32. public void push (Object o){
  33. list.add(o);
  34. }
  35. public int search (Object o){
  36. for(int i=0; i< this.getSize();i++)
  37. if(list.get(i).equals(o))
  38. return i;
  39. return -1;
  40. }
  41.  
  42. @Override
  43. public String toString() {
  44. return "MyStack{" + "list=" + list + '}';
  45. }
  46.  
  47.  
  48.  
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement