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

BIN
DEV3.2/TP8/Tri/Main.class Normal file

Binary file not shown.

16
DEV3.2/TP8/Tri/Main.java Normal file
View File

@@ -0,0 +1,16 @@
public class Main{
public static void main(String[] args) {
if (args.length==0){
System.out.println("Usage: java Main listereels");
}
Tri arbre = new Tri(Float.parseFloat(args[0]));
for(int i=0;i<args.length;i++){
arbre.ajouterNoeud(Float.parseFloat(args[i]));
}
System.out.println(arbre.toString());
}
}

BIN
DEV3.2/TP8/Tri/Noeud.class Normal file

Binary file not shown.

19
DEV3.2/TP8/Tri/Noeud.java Normal file
View File

@@ -0,0 +1,19 @@
public class Noeud{
protected float val;
protected Noeud noeudGauche;
protected Noeud noeudDroit;
public Noeud(float f){
this.val = f;
this.noeudGauche=null;
this.noeudDroit=null;
}
public void addNoeudGauche(float f){
this.noeudGauche = new Noeud(f);
}
public void addNoeudDroit(float f){
this.noeudDroit = new Noeud(f);
}
}

BIN
DEV3.2/TP8/Tri/Tri.class Normal file

Binary file not shown.

69
DEV3.2/TP8/Tri/Tri.java Normal file
View File

@@ -0,0 +1,69 @@
public class Tri{
private Noeud racine;
public Tri(float f){
this.racine = new Noeud(f);
}
public void ajouterNoeud(float f){
if(this.racine.val>f){
if(this.racine.noeudGauche==null){
this.racine.addNoeudGauche(f);
}
else{
this.ajouterNoeud(f,this.racine.noeudGauche);
}
}
else{
if(this.racine.noeudDroit==null){
this.racine.addNoeudDroit(f);
}
else{
this.ajouterNoeud(f,this.racine.noeudDroit);
}
}
}
public void ajouterNoeud(float f, Noeud n){
if(n.val>f){
if(n.noeudGauche==null){
n.addNoeudGauche(f);
}
else{
this.ajouterNoeud(f,n.noeudGauche);
}
}
else{
if(n.noeudDroit==null){
n.addNoeudDroit(f);
}
else{
this.ajouterNoeud(f,n.noeudDroit);
}
}
}
@Override
public String toString(){
String retour = "";
if(this.racine.noeudGauche!=null){
retour = toString(this.racine.noeudGauche) + retour;
}
if(this.racine.noeudDroit!=null){
retour = retour + " " + toString(this.racine.noeudDroit);
}
return retour;
}
public String toString(Noeud n){
String retour = " "+n.val;
if(n.noeudGauche!=null){
retour = toString(n.noeudGauche) + retour;
}
if(n.noeudDroit!=null){
retour = retour + " " + toString(n.noeudDroit);
}
return retour;
}
}