29 Novembre

This commit is contained in:
2023-11-29 17:27:03 +01:00
parent fae1f4c4c5
commit 9a4e1c622e
28 changed files with 355 additions and 0 deletions

Binary file not shown.

View File

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

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,21 @@
public class NoeudOperation extends Noeud{
public NoeudOperation(String ope){
this.val = ope;
for(int i=0;i<2;i++){
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);
}
}
}
protected void afficherNoeud(){
System.out.print(val+" ");
this.noeudGauche.afficherNoeud();
this.noeudDroit.afficherNoeud();
}
}