oups
This commit is contained in:
BIN
DEV3.2/Arbre/Repertoires/build/Noeud.class
Normal file
BIN
DEV3.2/Arbre/Repertoires/build/Noeud.class
Normal file
Binary file not shown.
BIN
DEV3.2/Arbre/Repertoires/build/repertoires.class
Normal file
BIN
DEV3.2/Arbre/Repertoires/build/repertoires.class
Normal file
Binary file not shown.
50
DEV3.2/Arbre/Repertoires/src/Noeud.java
Normal file
50
DEV3.2/Arbre/Repertoires/src/Noeud.java
Normal file
@@ -0,0 +1,50 @@
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* La classe Noeud représente un nœud dans une structure d'arbre.
|
||||
* Chaque nœud possède un identifiant unique (ID), un nom, un rang, et une liste d'enfants.
|
||||
*/
|
||||
public class Noeud {
|
||||
|
||||
|
||||
/** Le nom du nœud */
|
||||
public String name;
|
||||
|
||||
/** La liste des enfants du nœud */
|
||||
public ArrayList<Noeud> enfants;
|
||||
|
||||
|
||||
public Noeud(String nom) {
|
||||
this.name = nom;
|
||||
this.enfants = new ArrayList<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Ajoute un nœud en tant qu'enfant du nœud actuel.
|
||||
*
|
||||
* @param enfant Le nœud à ajouter en tant qu'enfant.
|
||||
*/
|
||||
public void ajouterEnfant(Noeud enfant) {
|
||||
this.enfants.add(enfant);
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtient la liste des enfants du nœud.
|
||||
*
|
||||
* @return La liste des enfants du nœud.
|
||||
*/
|
||||
public ArrayList<Noeud> getEnfants() {
|
||||
return enfants;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Obtient une représentation textuelle du nœud (son nom).
|
||||
*
|
||||
* @return Le nom du nœud.
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
52
DEV3.2/Arbre/Repertoires/src/repertoires.java
Normal file
52
DEV3.2/Arbre/Repertoires/src/repertoires.java
Normal file
@@ -0,0 +1,52 @@
|
||||
import java.io.*;
|
||||
|
||||
public class repertoires {
|
||||
public static void main(String args[])
|
||||
{
|
||||
|
||||
try {
|
||||
|
||||
File f = new File(args[0]);
|
||||
System.out.println("Files are:");
|
||||
|
||||
Noeud test = explo(f);
|
||||
afficherArbre(test);
|
||||
}
|
||||
catch (Exception e) {
|
||||
System.err.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private static Noeud explo(File f)
|
||||
{
|
||||
File[] files = f.listFiles();
|
||||
Noeud root = new Noeud(f.getName());
|
||||
if (files != null) {
|
||||
for (File fi : files) {
|
||||
Noeud node = new Noeud(fi.getName());
|
||||
node.ajouterEnfant(explo(fi));
|
||||
root.ajouterEnfant(root);
|
||||
}
|
||||
}
|
||||
|
||||
return root;
|
||||
}
|
||||
|
||||
public static void afficherArbre(Noeud racine) {
|
||||
afficherArbre(racine, 0);
|
||||
}
|
||||
|
||||
private static void afficherArbre(Noeud noeud, int niveau) {
|
||||
// Affiche le nœud actuel avec une indentation basée sur le niveau
|
||||
StringBuilder indentation = new StringBuilder();
|
||||
for (int i = 0; i < niveau; i++) {
|
||||
indentation.append(" "); // Deux espaces par niveau pour l'indentation
|
||||
}
|
||||
System.out.println(indentation.toString() + noeud);
|
||||
|
||||
// Appelle récursivement la méthode pour chaque enfant du nœud actuel
|
||||
for (Noeud enfant : noeud.getEnfants()) {
|
||||
afficherArbre(enfant, niveau + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user