/* Demonstration of Stack author: course: 15-111 Java Programming section: date: */ import java.io.*; import java.util.*; public class Stack { // default constructor public Stack () {V = new Vector();} // accessors public boolean empty(){ return (V.size()==0);} public boolean full(){return false;} public Object topOfStack() { return (V.elementAt(V.size()-1)); }// returns the top value of the stack public int sizeOfStack() { return V.size() ;} // returns the size of the stack // mutators // push a value to the top of the stack public void push(Object x){V.add(x);} public Object pop(){ if (!empty()) { Object temp = V.elementAt(V.size()-1); V.remove(V.size()-1); return temp; } else return null; } // remove the most recent item public void clear(){ while (!empty()) pop(); } // clear the entire stack public void print(){ for (int i=V.size()-1; i>=0;i--) System.out.println(((Integer)V.elementAt(i)).intValue()); } private Vector V; // is a pointer to the top element of the stack }