package stack;

public class StackExtensibleArray<E> extends StackFixedSizeArray<E> {

	private static final int INITIAL_SIZE = 8;

	public StackExtensibleArray(int size) {
		super(size);
	}

	public StackExtensibleArray() {
		this(INITIAL_SIZE);
	}

	@Override
	public void push(E shape) throws FullStackException {
		if (this.nbElements == this.elements.length) {
			Object[] tmp = new Object[this.elements.length * 2 + 1];
			for (int i = 0; i < this.elements.length; i++) {
				tmp[i] = this.elements[i];
			}
			this.elements = (E[]) tmp;
		}
		super.push(shape);
	}

}
