Merge branch 'master' of https://dwarves.iut-fbleau.fr/gitiut/sayebabu/DEV
This commit is contained in:
commit
b825103d79
BIN
DEV3.2/Arbre/ABR/src/ArbreBinaireRecherche.class
Normal file
BIN
DEV3.2/Arbre/ABR/src/ArbreBinaireRecherche.class
Normal file
Binary file not shown.
48
DEV3.2/Arbre/ABR/src/ArbreBinaireRecherche.java
Normal file
48
DEV3.2/Arbre/ABR/src/ArbreBinaireRecherche.java
Normal 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 "";
|
||||
}
|
||||
}
|
BIN
DEV3.2/Arbre/ABR/src/Main.class
Normal file
BIN
DEV3.2/Arbre/ABR/src/Main.class
Normal file
Binary file not shown.
14
DEV3.2/Arbre/ABR/src/Main.java
Normal file
14
DEV3.2/Arbre/ABR/src/Main.java
Normal 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));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
BIN
DEV3.2/Arbre/ABR/src/Noeud.class
Normal file
BIN
DEV3.2/Arbre/ABR/src/Noeud.class
Normal file
Binary file not shown.
13
DEV3.2/Arbre/ABR/src/Noeud.java
Normal file
13
DEV3.2/Arbre/ABR/src/Noeud.java
Normal 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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user