This commit is contained in:
Simon SAYE BABU 2023-12-06 15:41:29 +01:00
commit b825103d79
6 changed files with 75 additions and 0 deletions

Binary file not shown.

View File

@ -0,0 +1,48 @@
public class ArbreBinaireRecherche {
Noeud root;
public ArbreBinaireRecherche(int valeur) {
this.root = new Noeud(valeur);
}
public ArbreBinaireRecherche() {}
public void add(int val) {
root = addRecursif(root, val);
}
public Noeud addRecursif(Noeud current, int val) {
if (current == null) {
return new Noeud(val);
}
if (val < current.getValeur()) {
current.left = addRecursif(current.left, val);
} else if (val > current.getValeur()) {
current.right = addRecursif(current.right, val);
} else {
return current;
}
return current;
}
public void show() {
System.out.println("Affichage de l'arbre binaire de recherche (ordre infixe) :");
afficherInfixe(root);
System.out.println();
}
private void afficherInfixe(Noeud current) {
if (current != null) {
afficherInfixe(current.left);
System.out.print(current.getValeur() + " ");
afficherInfixe(current.right);
}
}
public String toString()
{
return "";
}
}

Binary file not shown.

View File

@ -0,0 +1,14 @@
public class Main {
public static void main(String[] args) {
if (args.length < 2) {
System.out.println("Utilisation incorecte: "+args[0]+" arg1 arg2 ...\nExemple: "+args[0]+" 1 4 5 3 8");
}
else
{
ArbreBinaireRecherche arbre = new ArbreBinaireRecherche();
for (String string : args) {
arbre.add(Integer.parseInt(string));
}
}
}
}

Binary file not shown.

View File

@ -0,0 +1,13 @@
public class Noeud {
Integer valeur;
Noeud left, right = null;
public Noeud(Integer etiquette) {
this.valeur = etiquette;
}
public int getValeur()
{
return valeur;
}
}