diff --git a/DEV3.2/Arbre/ABR/src/ArbreBinaireRecherche.class b/DEV3.2/Arbre/ABR/src/ArbreBinaireRecherche.class new file mode 100644 index 0000000..dabbd70 Binary files /dev/null and b/DEV3.2/Arbre/ABR/src/ArbreBinaireRecherche.class differ diff --git a/DEV3.2/Arbre/ABR/src/ArbreBinaireRecherche.java b/DEV3.2/Arbre/ABR/src/ArbreBinaireRecherche.java new file mode 100644 index 0000000..0732fbe --- /dev/null +++ b/DEV3.2/Arbre/ABR/src/ArbreBinaireRecherche.java @@ -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 ""; + } +} \ No newline at end of file diff --git a/DEV3.2/Arbre/ABR/src/Main.class b/DEV3.2/Arbre/ABR/src/Main.class new file mode 100644 index 0000000..223c5d1 Binary files /dev/null and b/DEV3.2/Arbre/ABR/src/Main.class differ diff --git a/DEV3.2/Arbre/ABR/src/Main.java b/DEV3.2/Arbre/ABR/src/Main.java new file mode 100644 index 0000000..73de375 --- /dev/null +++ b/DEV3.2/Arbre/ABR/src/Main.java @@ -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)); + } + } + } +} diff --git a/DEV3.2/Arbre/ABR/src/Noeud.class b/DEV3.2/Arbre/ABR/src/Noeud.class new file mode 100644 index 0000000..fe6bf12 Binary files /dev/null and b/DEV3.2/Arbre/ABR/src/Noeud.class differ diff --git a/DEV3.2/Arbre/ABR/src/Noeud.java b/DEV3.2/Arbre/ABR/src/Noeud.java new file mode 100644 index 0000000..a615290 --- /dev/null +++ b/DEV3.2/Arbre/ABR/src/Noeud.java @@ -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; + } +}