//Stack implementation using arrays

public class Stack
{
	int DEFAULT_MAX_SIZE = 100;
	int [] stack = new int[DEFAULT_MAX_SIZE];
	int topIndex = -1;	//the index of the top data element
	
	//default constructor
	public Stack()
	{
	}
	
	//specific constructor that sets the max size of the stack to size
	public Stack(int size)
	{
		stack = new int[size];
	}
	
	//push() takes data and pushes it onto the top of the stack
	
	public void push(int data)
	{
		if (!isFull())	//check if the stack is full
		{
			topIndex++;	//topIndex must be incremented to the next empty spot
			stack[topIndex] = data;	//set the data (place the tray)
		}
	}
	
	public int pop()
	{
		if (!isEmpty())	//check if stack is empty (cannot pop an empty stack)
		{
			topIndex--;	//decrement topIndex first to update the new topIndex
			return stack[topIndex+1];	//return the data
		}
		
		return -999;
	}
	
	//top() returns the data on top (no popping)
	public int top()
	{
		return stack[topIndex];	
	}
	
	//print() outputs all the elements in the stack
	public void print()
	{
		//start at topIndex and go down (print the stack from top to bottom)
		for (int i = topIndex; i >= 0; i--)
			System.out.println("Stack Index[" + i + "] => " + stack[i]);
	}
	
	//isEmpty() returns true if the stack is empty and false otherwise
	public boolean isEmpty()
	{
		if (topIndex == -1)
		{
			return true;
		}
		else
		{
			return false;
		}
		
		//return topIndex == -1;
	}
	
	//isFull() returns true if the stack is full and false otherwise
	public boolean isFull()
	{
		if (topIndex == stack.length-1)
		{
			return true;
		}
		else
		{
			return false;
		}
		
		//return topIndex == stack.length-1
	}
}