This commit is contained in:
2024-11-27 11:35:15 +01:00
parent 467af38a01
commit d39124f928
21 changed files with 902 additions and 56 deletions

Binary file not shown.

View File

@@ -0,0 +1,25 @@
import java.util.*;
public class Main {
protected static ArrayDeque<String> pile;
public static void main(String[] args) {
Main.pile = new ArrayDeque(args.length);
for (int i=0; i<args.length; i++){
Main.pile.push(args[i]);
}
Noeud noeudDeb;
String debutArbre = Main.pile.pop();
if (debutArbre.equals("+")||debutArbre.equals("-")||debutArbre.equals("x")||debutArbre.equals("/")){
noeudDeb = new NoeudOperation(debutArbre);
}
else{
noeudDeb = new NoeudChiffre(debutArbre);
}
noeudDeb.afficherNoeud();
System.out.print("\n");
}
}

Binary file not shown.

View File

@@ -0,0 +1,8 @@
public class Noeud{
protected String val;
protected Noeud noeudGauche;
protected Noeud noeudDroit;
protected void afficherNoeud(){
}
}

Binary file not shown.

View File

@@ -0,0 +1,11 @@
public class NoeudChiffre extends Noeud{
public NoeudChiffre(String n){
this.val = n;
}
protected void afficherNoeud(){
System.out.print(val);
}
}

Binary file not shown.

View File

@@ -0,0 +1,28 @@
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(')');
}
}