package senac_turma02.stack;

import senac_turma02.linkedlist.LinkedList;

public class StackImplLE<T extends Number> implements StackImpl<T> {

	@Override
	public boolean isEmpty() {
		return le_.isEmpty();
	}

	@Override
	public boolean isFull() {
		return false;
	}

	@SuppressWarnings("unchecked")
	@Override
	public T pop() throws StackEmptyException {
		T value = (T)le_.getLast();
		le_.extract(value);
		return value;		
	}

	@Override
	public void push(T n) throws StackFullException {
		le_.append(n);
	}

	@SuppressWarnings("unchecked")
	@Override
	public T top() throws StackEmptyException {
		
		return (T)le_.getLast();
	}
	
	/////////////////////////
	// Constructors
	/////////////////////////
	//
	// pilhaInicial[0] -> topo
	// pilhaInicial[1] -> topo - 1
	//
	public StackImplLE(T pilhaInicial[]) {
		le_ = new LinkedList();

		for( T elem : pilhaInicial ) {
			le_.prepend(elem);
		}
	}
	public StackImplLE() {
		le_ = new LinkedList();
	}	
	/////////////////////////////////////////////
	// Implementation
	// Stack com LE incluindo elementos no final
	/////////////////////////////////////////////
    private LinkedList le_;
}
