public class stack2 {
	
	private Object[] items;
	private int top;
	final private static int DEFAULT_SIZE = 10;
	
	public stack2() {
		items = new Object[DEFAULT_SIZE];
		top = -1;
	}
	
	// Pushes the item x onto the top of the stack, if there
	// is room and returns true. If there is no room, false
	// is returned an no change is made to the stack.
	public boolean push(Object obj) {
		
		// full stack case
		if (top == DEFAULT_SIZE-1)
			return false;
			
		// Add obj to the top of the stack.
		top = top + 1;
		items[top] = obj;
		return true;
	}
	
	// Pops and returns the item from the top of the stack.
	// If there is no such item, null is returned.
	public Object pop() {
		
		if (top == -1)
			return null;
			
		// Get the item at the top, change the top and return
		// the item.
		Object itemToReturn = items[top];
		top = top - 1;
		return itemToReturn;
	}
	
	public boolean empty() {
		return (top == -1);
	}
	
	public boolean full() {
		return (top == DEFAULT_SIZE-1);
	}
	
	public Object top() {
		if (top == -1)
			return null;
		return items[top];
	}
	
}