package ab;

 /** Classe décrivant une énumération infixe parenthésée d'un arbre binaire. */
public class EnumerationInfixePar extends EnumerationArbre {
  private boolean par =false;
  public EnumerationInfixePar(ArbreBinaire a) {
    super(a);
    if (this.a.gauche != null) this.eag=new EnumerationInfixePar(this.a.gauche);
    if (this.a.droit != null) this.ead=new EnumerationInfixePar(this.a.droit);
    }

    public boolean hasMoreElements() { return super.hasMoreElements()|| par; }

    public Object nextElement() {
      if (!par && (this.a.gauche != null || this.a.droit != null)) {
         par=true;return "(";}
      if (this.eag != null && this.eag.hasMoreElements()) 
         return this.eag.nextElement();
      if (!racineEnumeree) {this.racineEnumeree=true;return this.a.racine;}
      if (this.ead != null)
          if (this.ead.hasMoreElements()) return this.ead.nextElement();
      if (par) {par=false;return(")");}
      return null;
      }
}

