Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.Stack;
- public class stackInterface extends ArrayBasedDataStructuresDriver {
- private ArrayList<Object> list = new ArrayList<Object>(100);
- private Stack<Object> st = new Stack<Object>();
- private int size = 0;
- public void push(Object in){ //pushes an object into the stack
- list.add(st.push(in));
- size++;
- }
- public Object pop(){ //pops the object out of the stack
- size--;
- return list.remove(st.pop());
- }
- public int size(){ //checks the size of the stack
- return st.size();
- }
- public Object peek(){ //checks the top of the stack, but does not pop it
- return st.peek();
- }
- public String toString(){ //print out the string of the stack
- String retval = "";
- for(int i = 0 ; i < list.size();i ++){
- retval = retval + list.get(i);
- }
- return retval;
- }
- public boolean isEmpty(){ //check to see if stack is empty
- return(st.empty());
- }
- public boolean equals(Object other){ //check to see if two stacks are equivalent
- while(!isEmpty()){
- if(!st.pop().equals(((stackInterface) other).pop())){
- return false;
- }
- }
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement