public class StackAdt
{
	private Object[] stack;
	private int pointer, capacity;
	
	public StackAdt(int n)
	{
		capacity = n;
		stack = new Object[n];
		pointer = -1;
	}
	
	public void push(Object ch)
	//pre: isFull is false
	{
		if(isFull() )
		{
			throw new IndexOutOfBoundsException("push a full stack");
		}
		pointer++;
		stack[pointer] = ch;
	}
	
	public Object pop()
	//pre: stack not empty
	{
		if(isEmpty() )
		{
			throw new IndexOutOfBoundsException("pops an empty stack");
		}
		Object temp = stack[pointer];
		pointer--;
		return temp;
	}
	
	public Object peek()
	//pre: stack not empty
	{
		if(isEmpty() )
		{
			throw new IndexOutOfBoundsException("peeks at an empty stack");
		}
		return stack[pointer];
	}
	
	public boolean isFull()
	{
		return capacity == pointer + 1;
	}
	
	public boolean isEmpty()
	{
		return pointer == -1;		
	}
	
	public int size()
	{
		return pointer + 1;
	}
}
