package senac_turma02.stack;

public class StackImpl {
	/////////////////////////
	// Interface
	/////////////////////////
	public int pop() {
		return data_[topIndex_--];
	}
	public void push(int n) {
		data_[++topIndex_] = n;
	}
	public int top() {
		return data_[topIndex_];
	}
	public boolean isEmpty() {
		return topIndex_ == -1 ? true: false;
	}
	public boolean isFull() {
		return topIndex_ == size_-1 ? true: false;
	}
	public StackImpl(int pilhaInicial[]) {
		size_     = pilhaInicial.length;
		topIndex_ = size_ - 1;		
		data_     = new int[size_];

		int i = topIndex_;
		for( int elem : pilhaInicial ) {
			data_[i--] = elem;
		}
	}
	public StackImpl(int size) {
		size_     = size;
		topIndex_ = -1;		
		data_     = new int[size_];
	}
	public StackImpl() {
		this(1);
	}	
	/////////////////////////
	// Implementation
	/////////////////////////
	private int size_;
	private int data_[];
	private int topIndex_;
}

