public class IntegerStack { IntegerList stackData; public IntegerStack( ){ stackData = new IntegerArrayList(); } public IntegerStack( int[] initialData ){ stackData = new IntegerArrayList( initialData ); } public IntegerStack( IntegerList initialList ){ stackData = new IntegerArrayList( initialList ); } /* Pushes parameter integer onto top of stack * Returns the index of the element; */ public int push( int integer ){ return stackData.add( integer ); } /* Pops the top of the stack * Returns the element popped off */ public int pop(){ return stackData.remove( stackData.size() - 1); } /* Returns the full size of the containing array */ public int capacity(){ return stackData.capacity(); } /* Returns true if there are 0 elements in the list */ public boolean isEmpty(){ return stackData.isEmpty(); } /* Returns a copy of all the elements in the array; size = size() */ public int[] toArray(){ return stackData.toArray(); } /* Returns a String representation of the elements in the array; * (non-Javadoc) * @see java.lang.Object#toString() */ public String toString(){ return stackData.toString(); } /* Returns the number of elements in the list */ public int size(){ return stackData.size(); } public static void main(String[] args){ int[] init = { 44, 55, 66}; IntegerStack test = new IntegerStack( init ); for( int i = 0; i < 10; ++i ){ test.push(i); } System.out.println( test.toString() ); while( test.size() > 5){ test.pop(); } System.out.println( test.toString() ); for( int i = 11; i < 44; i += 11){ test.push(i); } System.out.println( test.toString() ); while( !test.isEmpty() ) System.out.print( test.pop() +", " ); } }