public class Stack {

	private E[] stack;
	private int next = 0;  // index of last item in stack + 1

	public Stack(int size) {
		//create an array large enough to hold the stack
		stack = (E[]) new Object[size];
	}

	public void push(E on) {
		if (next < stack.length)
		   stack[next++] = on;
	}
	public boolean isEmpty() {
		return (next == 0);
	}

	public E pop(){
		if (!isEmpty())
		   return stack[--next]; // top item on stack
		else
		   return null;
	}

	public int getSize() {
		return next;
	}

	public class StepThrough {
		private int i = 0;

		public void increment() {
			if (i < stack.length) i++;
		}

		public E current() {
			return stack[i];
		}

		public boolean isLast() {
			return(i == getSize() - 1);
		}
	}

}