28 lines
860 B
Java
28 lines
860 B
Java
public class NoeudOperation extends Noeud{
|
|
|
|
public NoeudOperation(String ope){
|
|
this.val = ope;
|
|
String prochainNoeud = Main.pile.pop();
|
|
if (prochainNoeud.equals("+")||prochainNoeud.equals("-")||prochainNoeud.equals("x")||prochainNoeud.equals("/")){
|
|
this.noeudGauche = new NoeudOperation(prochainNoeud);
|
|
}
|
|
else{
|
|
this.noeudGauche = new NoeudChiffre(prochainNoeud);
|
|
}
|
|
String prochainNoeud2 = Main.pile.pop();
|
|
if (prochainNoeud2.equals("+")||prochainNoeud2.equals("-")||prochainNoeud2.equals("x")||prochainNoeud2.equals("/")){
|
|
this.noeudDroit = new NoeudOperation(prochainNoeud2);
|
|
}
|
|
else{
|
|
this.noeudDroit = new NoeudChiffre(prochainNoeud2);
|
|
}
|
|
}
|
|
|
|
protected void afficherNoeud(){
|
|
System.out.print('(');
|
|
this.noeudDroit.afficherNoeud();
|
|
System.out.print(val);
|
|
this.noeudGauche.afficherNoeud();
|
|
System.out.print(')');
|
|
}
|
|
} |