package Exo1;

import java.util.LinkedList;

public class Pile<T> {
	LinkedList<T> pile;
	private int taille;
	public Pile(int taille) {
		pile = new LinkedList<T>();
	}
	public void empiler(T x) throws IllegalStateException {
		if(pile.size() < taille) {
			throw new IllegalStateException("La pile est pleine !");
		}
		pile.addFirst(x);;
	}
	public T depiler() throws IllegalStateException {
		if(pile.size() == 0) {
			throw new IllegalStateException("La pile est vide !");
		}
		return pile.removeFirst();
	}
	public T getSommet() throws IllegalStateException {
		if(pile.size() == 0) {
			throw new IllegalStateException("La pile est vide !");
		}
		return pile.getFirst();
	}
	public boolean estPleine( ) {
		return pile.size() == taille;
	}
	public boolean estVide() {
		return  pile.isEmpty();
	}
	
}
