/* * Created on 15 nov. 2004 * */ package arbre; /** * @author baudon * */ public class Arbre { private Arbre gauche; private Arbre droit; private T data; private Arbre pere = null; private void traiterFils(Arbre fils, String type) { if (fils != null) { if (fils.pere != null) { throw new IllegalArgumentException("fils " + type + " invalide"); } fils.pere = this; } } public Arbre(Arbre gauche, Arbre droit, T data) { traiterFils(gauche, "gauche"); this.gauche = gauche; traiterFils(droit, "droit"); this.droit = droit; this.data = data; } public Arbre droit() { return droit; } public Arbre gauche() { return gauche; } public Arbre pere() { return pere; } public T data() { return data; } public boolean racine() { return pere == null; } public boolean feuille() { return gauche == null && droit == null; } }