DEV/DEV3.2/TP7/Prefixe/NoeudOperation.java

26 lines
814 B
Java
Raw Normal View History

2023-11-29 17:27:03 +01:00
public class NoeudOperation extends Noeud{
public NoeudOperation(String ope){
this.val = ope;
2024-11-27 11:35:15 +01:00
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);
2023-11-29 17:27:03 +01:00
}
}
protected void afficherNoeud(){
System.out.print(val+" ");
this.noeudDroit.afficherNoeud();
2024-11-27 11:35:15 +01:00
this.noeudGauche.afficherNoeud();
2023-11-29 17:27:03 +01:00
}
}