Maj du git depuis la derniere fois
This commit is contained in:
BIN
TP_DEV3.2/Arbres/Node.class
Normal file
BIN
TP_DEV3.2/Arbres/Node.class
Normal file
Binary file not shown.
50
TP_DEV3.2/Arbres/Node.java
Normal file
50
TP_DEV3.2/Arbres/Node.java
Normal file
@@ -0,0 +1,50 @@
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class Node {
|
||||
|
||||
String name;
|
||||
List<Node> children = new ArrayList<>();
|
||||
|
||||
public Node(String name){
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void addChild(Node child){
|
||||
children.add(child);
|
||||
}
|
||||
|
||||
public void afficher(String indent){
|
||||
System.out.println(indent + name);
|
||||
for(Node c : children){
|
||||
c.afficher(indent + " "); // indentation augmentée
|
||||
}
|
||||
}
|
||||
|
||||
public static Node build(File f){
|
||||
Node n = new Node(f.getName());
|
||||
File[] list = f.listFiles();
|
||||
|
||||
if(list != null){
|
||||
for(File child : list){
|
||||
n.addChild(build(child)); // récursion OK
|
||||
}
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
if(args.length != 1){
|
||||
System.out.println("Usage : java Node <repertoire>");
|
||||
return; // éviter un crash
|
||||
}
|
||||
|
||||
File fichier = new File(args[0]);
|
||||
Node tree = build(fichier);
|
||||
tree.afficher("");
|
||||
}
|
||||
}
|
||||
39
TP_DEV3.2/Arbres/Prefixe.java
Normal file
39
TP_DEV3.2/Arbres/Prefixe.java
Normal file
@@ -0,0 +1,39 @@
|
||||
public class Prefixe {
|
||||
|
||||
|
||||
String value;
|
||||
Prefixe left;
|
||||
Prefixe right;
|
||||
|
||||
public Prefixe(String v) {
|
||||
this.value = v;
|
||||
}
|
||||
|
||||
public boolean isOperator() {
|
||||
return "+-*/".contains(value);
|
||||
}
|
||||
|
||||
public static int index = 0;
|
||||
|
||||
public static Prefixe build(String[] t) {
|
||||
String token = t[index++];
|
||||
Prefixe p = new Prefixe(token);
|
||||
|
||||
if (p.isOperator()) {
|
||||
p.left = build(t);
|
||||
p.right = build(t);
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -27,7 +27,7 @@ public afficher(String nom){
|
||||
|
||||
for(Node c : children){
|
||||
|
||||
c.print(nom+"");
|
||||
c.print(nom+" ");
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,73 +0,0 @@
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class Repertoires {
|
||||
|
||||
|
||||
String name;
|
||||
List<Node> children = new ArrayList<>();
|
||||
|
||||
public Node(String name){
|
||||
|
||||
this.name=name;
|
||||
|
||||
}
|
||||
|
||||
public addChild(Node child){
|
||||
|
||||
children.add(child);
|
||||
|
||||
}
|
||||
|
||||
public afficher(String nom){
|
||||
|
||||
System.out.println(nom+name);
|
||||
|
||||
for(Node c : children){
|
||||
|
||||
c.print(nom+"");
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
public static Node build(File f){
|
||||
|
||||
Node n = new Node(file.getName());
|
||||
File[] list = f.listFiles();
|
||||
if(list!=null){
|
||||
|
||||
for(File child : list){
|
||||
|
||||
n.addChild(build(child));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return n;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
File fichier = New File(args[0]);
|
||||
Node tree = build(Dictionnaire);
|
||||
|
||||
tree.afficher("");
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user