Advertisement
Guest User

Untitled

a guest
Apr 21st, 2015
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.Stack;
  3.  
  4.  
  5. public class stackInterface extends ArrayBasedDataStructuresDriver {
  6.  
  7. private ArrayList<Object> list = new ArrayList<Object>(100);
  8. private Stack<Object> st = new Stack<Object>();
  9. private int size = 0;
  10.  
  11. public void push(Object in){ //pushes an object into the stack
  12. list.add(st.push(in));
  13. size++;
  14. }
  15. public Object pop(){ //pops the object out of the stack
  16. size--;
  17. return list.remove(st.pop());
  18. }
  19. public int size(){ //checks the size of the stack
  20. return st.size();
  21. }
  22. public Object peek(){ //checks the top of the stack, but does not pop it
  23. return st.peek();
  24. }
  25. public String toString(){ //print out the string of the stack
  26. String retval = "";
  27. for(int i = 0 ; i < list.size();i ++){
  28. retval = retval + list.get(i);
  29. }
  30. return retval;
  31. }
  32. public boolean isEmpty(){ //check to see if stack is empty
  33. return(st.empty());
  34. }
  35.  
  36. public boolean equals(Object other){ //check to see if two stacks are equivalent
  37. while(!isEmpty()){
  38. if(!st.pop().equals(((stackInterface) other).pop())){
  39. return false;
  40. }
  41. }
  42. return true;
  43. }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement