public class StachADT
    //the stackADT implemented by a linked list
{
	private int pointer;
    private	Link stack;
	
	public StachADT(int n)//simulates array implemen constructor
	{
		pointer = -1;
		stack = null;
	}
	
	public boolean isEmpty()
	{
		return stack == null;
	}
	
	public boolean isFull()
	{
		return false;
	}
	
	public Object peek()
	{
		if(isEmpty() )
		{
			throw new EmptyException("stack is MT");
		}
		return stack.data;
	}
	
	public void push(Object obj)
	{
		pointer++;
		Link temp = new Link();
		temp.data = obj;
		temp.next = stack;
		stack = temp;
	}
	
	public Object pop()
	{
		if(isEmpty() )
		{
			throw new EmptyException("stack is MT");
		}
		pointer--;
		Object temp = stack.data;
		stack = stack.next;//advance stack one node
		return temp;
	}
	
	public int size()
	{
		return pointer + 1;
	}
		
}

class Link
{
	Object data;
	Link next;
}

class EmptyException extends RuntimeException
{
	public EmptyException()
	{
		super();
	}
	
	public EmptyException(String s)
	{
		super(s);
	}
}

