package Arbre;

public class ABR {
	private Float valeur;
	private ABR filsGauche, filsDroit;
	
	public ABR() {}
	
	public boolean isEmpty() {
		return this.valeur == null;
	}
	
	public void ajouter(Float valeur) {
		if(this.isEmpty()) {
			this.valeur = valeur;
			this.filsGauche = new ABR();
			this.filsDroit = new ABR();
		}
		else {
			if (valeur <= this.valeur) {
				this.filsGauche.ajouter(valeur);
			}
			else {
				this.filsDroit.ajouter(valeur);
			}
		}
	}
	
	@Override
	public String toString() {
		if(isEmpty()) {
			return "";
		}
		else {
			return this.filsGauche.toString() + this.valeur + " " + this.filsDroit.toString();
		}
	}
	
	public String structureToString() {
		if(isEmpty()) {
			return "[]";
		}
		else {
			return "[" + String.format("%1$.2f", this.valeur) + this.filsGauche.structureToString() + this.filsDroit.structureToString() + "]";
		}
	}
	
}
