dhgfhuje
This commit is contained in:
BIN
DEV/DEV3.2/TP07_Arbres/Arbre.class
Normal file
BIN
DEV/DEV3.2/TP07_Arbres/Arbre.class
Normal file
Binary file not shown.
99
DEV/DEV3.2/TP07_Arbres/Arbre.java
Normal file
99
DEV/DEV3.2/TP07_Arbres/Arbre.java
Normal file
@@ -0,0 +1,99 @@
|
||||
import java.util.*;
|
||||
|
||||
public class Arbre<E>{
|
||||
private Noeud<E> racine;
|
||||
private String strArbre;
|
||||
|
||||
public Arbre(){
|
||||
}
|
||||
|
||||
public Arbre(E racine){
|
||||
this.racine = new Noeud<E>(racine);
|
||||
}
|
||||
|
||||
public Arbre(Noeud<E> racine){
|
||||
this.racine = racine;
|
||||
}
|
||||
|
||||
public void setRacine(E racine){
|
||||
this.racine = new Noeud<E>(racine);
|
||||
}
|
||||
|
||||
public Noeud<E> getRacine(){
|
||||
return this.racine;
|
||||
}
|
||||
|
||||
public void afficheArbre(){
|
||||
this.strArbre = "";
|
||||
this.updateStrArbre(this.racine, 0);
|
||||
System.out.println(this.strArbre);
|
||||
}
|
||||
|
||||
public void afficheArbreQ2(){
|
||||
this.strArbre = "";
|
||||
this.updateStrArbreQ2(this.racine);
|
||||
System.out.println(this.strArbre);
|
||||
}
|
||||
|
||||
public void afficheArbreQ3(){
|
||||
this.strArbre = "";
|
||||
this.updateStrArbreQ3(this.racine);
|
||||
System.out.println(this.strArbre);
|
||||
}
|
||||
|
||||
private void updateStrArbreQ3(Noeud<E> noeud){
|
||||
try{
|
||||
String valeur = noeud.getValue().toString();
|
||||
if (valeur.equals("x") || valeur.equals("/") || valeur.equals("+") || valeur.equals("-")){
|
||||
this.strArbre += "(";
|
||||
}
|
||||
else{
|
||||
this.strArbre += valeur;
|
||||
}
|
||||
List<Noeud<E>> fils = noeud.getFils();
|
||||
for (int i=0; i<fils.size(); i++){
|
||||
this.updateStrArbreQ3(fils.get(i));
|
||||
if (i == 0){
|
||||
this.strArbre += valeur;
|
||||
}
|
||||
if (i == 1){
|
||||
this.strArbre += ")";
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (NullPointerException e){
|
||||
this.strArbre += "null";
|
||||
}
|
||||
}
|
||||
|
||||
private void updateStrArbreQ2(Noeud<E> noeud){
|
||||
try{
|
||||
this.strArbre += noeud.getValue().toString() + " ";
|
||||
List<Noeud<E>> fils = noeud.getFils();
|
||||
for (int i=0; i<fils.size(); i++){
|
||||
this.updateStrArbreQ2(fils.get(i));
|
||||
}
|
||||
}
|
||||
catch (NullPointerException e){
|
||||
this.strArbre += "null";
|
||||
}
|
||||
}
|
||||
|
||||
private void updateStrArbre(Noeud<E> noeud, int profondeur){
|
||||
int i;
|
||||
this.strArbre += "\n";
|
||||
for (i=0; i<profondeur; i++){
|
||||
this.strArbre += " ";
|
||||
}
|
||||
try{
|
||||
this.strArbre += noeud.getValue().toString();
|
||||
List<Noeud<E>> fils = noeud.getFils();
|
||||
for (i=0; i<fils.size(); i++){
|
||||
this.updateStrArbre(fils.get(i), profondeur+1);
|
||||
}
|
||||
}
|
||||
catch (NullPointerException e){
|
||||
this.strArbre += "null";
|
||||
}
|
||||
}
|
||||
}
|
||||
BIN
DEV/DEV3.2/TP07_Arbres/Noeud.class
Normal file
BIN
DEV/DEV3.2/TP07_Arbres/Noeud.class
Normal file
Binary file not shown.
23
DEV/DEV3.2/TP07_Arbres/Noeud.java
Normal file
23
DEV/DEV3.2/TP07_Arbres/Noeud.java
Normal file
@@ -0,0 +1,23 @@
|
||||
import java.util.*;
|
||||
|
||||
public class Noeud<E>{
|
||||
private E valeur;
|
||||
private List<Noeud<E>> fils;
|
||||
|
||||
public Noeud(E valeur){
|
||||
this.valeur = valeur;
|
||||
this.fils = new ArrayList<Noeud<E>>();
|
||||
}
|
||||
|
||||
public E getValue(){
|
||||
return this.valeur;
|
||||
}
|
||||
|
||||
public List<Noeud<E>> getFils(){
|
||||
return this.fils;
|
||||
}
|
||||
|
||||
public void add(Noeud<E> fils){
|
||||
this.fils.add(fils);
|
||||
}
|
||||
}
|
||||
BIN
DEV/DEV3.2/TP07_Arbres/Q1File.class
Normal file
BIN
DEV/DEV3.2/TP07_Arbres/Q1File.class
Normal file
Binary file not shown.
33
DEV/DEV3.2/TP07_Arbres/Q1File.java
Normal file
33
DEV/DEV3.2/TP07_Arbres/Q1File.java
Normal file
@@ -0,0 +1,33 @@
|
||||
import java.io.*;
|
||||
|
||||
public class Q1File extends File{
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public Q1File(String pathname){
|
||||
super(pathname);
|
||||
}
|
||||
|
||||
public static Q1File[] convertion(File[] listeBrute){
|
||||
if (listeBrute == null){
|
||||
return null;
|
||||
}
|
||||
Q1File[] listeFinal = new Q1File[listeBrute.length];
|
||||
for (int i=0; i<listeBrute.length; i++){
|
||||
listeFinal[i] = Q1File.convertion(listeBrute[i]);
|
||||
}
|
||||
return listeFinal;
|
||||
}
|
||||
|
||||
public static Q1File convertion(File repertoire){
|
||||
if (repertoire == null){
|
||||
return null;
|
||||
}
|
||||
return new Q1File(repertoire.getAbsolutePath());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(){
|
||||
return this.getName();
|
||||
}
|
||||
}
|
||||
BIN
DEV/DEV3.2/TP07_Arbres/Q1Main.class
Normal file
BIN
DEV/DEV3.2/TP07_Arbres/Q1Main.class
Normal file
Binary file not shown.
31
DEV/DEV3.2/TP07_Arbres/Q1Main.java
Normal file
31
DEV/DEV3.2/TP07_Arbres/Q1Main.java
Normal file
@@ -0,0 +1,31 @@
|
||||
import java.util.*;
|
||||
import java.io.*;
|
||||
|
||||
public class Q1Main{
|
||||
private static Arbre<Q1File> arbre;
|
||||
|
||||
public static void main(String args[]){
|
||||
try{
|
||||
Q1File racine = new Q1File(args[0]);
|
||||
Q1Main.arbre = new Arbre<Q1File>(racine);
|
||||
Q1Main.recursive(racine, arbre.getRacine());
|
||||
Q1Main.arbre.afficheArbre();
|
||||
}
|
||||
catch(ArrayIndexOutOfBoundsException e){
|
||||
System.out.println(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void recursive(Q1File repertoire, Noeud<Q1File> noeud){
|
||||
if (repertoire != null){
|
||||
Q1File[] contenu = Q1File.convertion(repertoire.listFiles());
|
||||
if (contenu != null){
|
||||
for (Q1File item : contenu){
|
||||
Noeud<Q1File> newFils = new Noeud<Q1File>(item);
|
||||
noeud.add(newFils);
|
||||
Q1Main.recursive(item, newFils);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
BIN
DEV/DEV3.2/TP07_Arbres/Q2Main.class
Normal file
BIN
DEV/DEV3.2/TP07_Arbres/Q2Main.class
Normal file
Binary file not shown.
34
DEV/DEV3.2/TP07_Arbres/Q2Main.java
Normal file
34
DEV/DEV3.2/TP07_Arbres/Q2Main.java
Normal file
@@ -0,0 +1,34 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.util.*;
|
||||
|
||||
public class Q2Main{
|
||||
public static void main(String[] args) {
|
||||
|
||||
ArrayDeque<Noeud<String>> liste = new ArrayDeque<>();
|
||||
try{
|
||||
for (int i=0; i<args.length; i++){
|
||||
if (args[i].equals("x") || args[i].equals("/") || args[i].equals("+") || args[i].equals("-")){
|
||||
Noeud<String> a = liste.pop();
|
||||
Noeud<String> b = liste.pop();
|
||||
Noeud<String> c = new Noeud<String>(args[i]);
|
||||
c.add(b);
|
||||
c.add(a);
|
||||
liste.push(c);
|
||||
}
|
||||
else{
|
||||
liste.push(new Noeud<String>(args[i]));
|
||||
}
|
||||
}
|
||||
Arbre<String> arbre = new Arbre<>(liste.pop());
|
||||
arbre.afficheArbreQ2();
|
||||
arbre.afficheArbreQ3();
|
||||
}
|
||||
catch(NoSuchElementException e){
|
||||
System.out.println("tu ecrit bien");
|
||||
}
|
||||
catch(NumberFormatException e){
|
||||
System.out.println("arretes de mal executer le code");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user