29 Novembre

This commit is contained in:
Adrian POURCHOT 2023-11-29 17:27:03 +01:00
parent fae1f4c4c5
commit 9a4e1c622e
28 changed files with 355 additions and 0 deletions

Binary file not shown.

View File

@ -0,0 +1,55 @@
import java.util.*;
public class Main{
public static ArrayDeque<Float> scinder(ArrayDeque<Float> file){
ArrayDeque<Float> nouveaufile = new ArrayDeque(file.size()/2);
for (int i=0; i<(file.size()/2); i++){
nouveaufile.add(file.poll());
}
return nouveaufile;
}
public static ArrayDeque<Float> fusionner(ArrayDeque<Float> fileun, ArrayDeque<Float> filedeux){
for (int i=0; i<(filedeux.size()); i++){
fileun.add(filedeux.poll());
}
return fileun;
}
public static ArrayDeque<Float> trier(ArrayDeque<Float> file){
switch (file.size()){
case 1:
return file;
case 2:
if (file.getFirst()>file.getLast()){
file.add(file.poll());
}
return file;
default:
ArrayDeque<Float> nouveaufile = new ArrayDeque(file.size()/2);
nouveaufile=scinder(file);
return fusionner(trier(nouveaufile),trier(file));
}
}
public static void main(String[] args) {
ArrayDeque<Float> file = new ArrayDeque(args.length);
for (int i=0; i<args.length; i++){
file.add(Float.parseFloat(args[i]));
}
file=trier(file);
for (int i=0; i<args.length; i++){
System.out.println(""+file.poll()+"\n");
}
}
}

Binary file not shown.

View File

@ -0,0 +1,12 @@
import java.util.*;
public class Main {
public static void main (String[] args){
Map<Thread,StackTraceElement[]> dico =Thread.getAllStackTraces();
Set<Map.Entry<Thread,StackTraceElement[]>> tab=dico.entrySet();
Iterator ite=tab.iterator();
for (;ite.hasNext();){
System.out.println(ite.next()+"\n");
}
}
}

Binary file not shown.

View File

@ -0,0 +1,24 @@
import java.util.*;
public class Main {
protected static ArrayDeque<String> pile;
public static void main(String[] args) {
Main.pile = new ArrayDeque(args.length);
for (int i=0; i<args.length; i++){
Main.pile.push(args[i]);
}
Noeud noeudDeb;
String debutArbre = Main.pile.pop();
if (debutArbre.equals("+")||debutArbre.equals("-")||debutArbre.equals("x")||debutArbre.equals("/")){
noeudDeb = new NoeudOperation(debutArbre);
}
else{
noeudDeb = new NoeudChiffre(debutArbre);
}
noeudDeb.afficherNoeud();
}
}

Binary file not shown.

View File

@ -0,0 +1,8 @@
public class Noeud{
protected String val;
protected Noeud noeudGauche;
protected Noeud noeudDroit;
protected void afficherNoeud(){
}
}

Binary file not shown.

View File

@ -0,0 +1,11 @@
public class NoeudChiffre extends Noeud{
public NoeudChiffre(String n){
this.val = n;
}
protected void afficherNoeud(){
System.out.print(val+" ");
}
}

Binary file not shown.

View File

@ -0,0 +1,21 @@
public class NoeudOperation extends Noeud{
public NoeudOperation(String ope){
this.val = ope;
for(int i=0;i<2;i++){
String prochainNoeud = Main.pile.pop();
if (prochainNoeud.equals("+")||prochainNoeud.equals("-")||prochainNoeud.equals("x")||prochainNoeud.equals("/")){
this.noeudGauche = new NoeudOperation(prochainNoeud);
}
else{
this.noeudGauche = new NoeudChiffre(prochainNoeud);
}
}
}
protected void afficherNoeud(){
System.out.print(val+" ");
this.noeudGauche.afficherNoeud();
this.noeudDroit.afficherNoeud();
}
}

Binary file not shown.

View File

@ -0,0 +1,8 @@
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args){
Repertoires main = new Repertoires(args[0]);
}
}

Binary file not shown.

View File

@ -0,0 +1,62 @@
import java.io.*;
import java.util.*;
public class Noeud{
private File f;
private Noeud n1=null;
private Noeud n2=null;
private Noeud n3=null;
private Noeud n4=null;
public Noeud(File s){
this.f = s;
}
/*public Noeud(String s, Noeud noeud1){java.io.File
}
public Noeud(String s, Noeud noeud1, Noeud noeud2, Noeud noeud3){
this.f = new File(s);
this.noeud1=n1;
this.noeud2=n2;
this.noeud3=n3;
}
public Noeud(String s, Noeud noeud1, Noeud noeud2, Noeud noeud3, Noeud noeud4){
this.f = new File(s);
this.noeud1=n1;
this.noeud2=n2;
this.noeud3=n3;
this.noeud4=n4;
}*/
public void add(Noeud n){
if(n1!=null){
if(n2!=null){
if(n3!=null){
n4=n;
return;
}
n3=n;
return;
}
n2=n;
return;
}
n1=n;
return;
}
public File getFile(){
return this.f;
}
public Noeud getN1(){
return this.n1;
}
public Noeud getN2(){
return this.n2;
}
public Noeud getN3(){
return this.n3;
}
public Noeud getN4(){
return this.n4;
}
}

Binary file not shown.

View File

@ -0,0 +1,50 @@
import java.io.*;
import java.util.*;
public class Repertoires{
public Repertoires(String s){
File f = new File(s);
ArrayDeque<File> a = new ArrayDeque<File>();
a.add(f);
Noeud n=this.tree(a);
this.afficher(n,0);
}
public Noeud tree(ArrayDeque<File> a){
File f = a.remove();
if(f.isFile()){
Noeud n = new Noeud(f);
return n;
}
if(f.isDirectory()){
Noeud n = new Noeud(f);
File[] liste = f.listFiles();
for(int i=0;i<liste.length;i++){
a.add(liste[i]);
Noeud m=this.tree(a);
n.add(m);
}
return n;
}
return null;
}
public void afficher(Noeud n,int i){
String chaine="";
for(int j=0;j<i;j++){
chaine = chaine+" ";
}
chaine = chaine+n.getFile().getName();
System.out.println(chaine);
if(n.getN1()!=null){
afficher(n.getN1(),i+1);
if(n.getN2()!=null){
afficher(n.getN2(),i+1);
if(n.getN3()!=null){
afficher(n.getN3(),i+1);
if(n.getN4()!=null){
afficher(n.getN4(),i+1);
}
}
}
}
}
}

View File

BIN
DEV3.2/TP8/Tri/Main.class Normal file

Binary file not shown.

16
DEV3.2/TP8/Tri/Main.java Normal file
View File

@ -0,0 +1,16 @@
public class Main{
public static void main(String[] args) {
if (args.length==0){
System.out.println("Usage: java Main listereels");
}
Tri arbre = new Tri(Float.parseFloat(args[0]));
for(int i=0;i<args.length;i++){
arbre.ajouterNoeud(Float.parseFloat(args[i]));
}
System.out.println(arbre.toString());
}
}

BIN
DEV3.2/TP8/Tri/Noeud.class Normal file

Binary file not shown.

19
DEV3.2/TP8/Tri/Noeud.java Normal file
View File

@ -0,0 +1,19 @@
public class Noeud{
protected float val;
protected Noeud noeudGauche;
protected Noeud noeudDroit;
public Noeud(float f){
this.val = f;
this.noeudGauche=null;
this.noeudDroit=null;
}
public void addNoeudGauche(float f){
this.noeudGauche = new Noeud(f);
}
public void addNoeudDroit(float f){
this.noeudDroit = new Noeud(f);
}
}

BIN
DEV3.2/TP8/Tri/Tri.class Normal file

Binary file not shown.

69
DEV3.2/TP8/Tri/Tri.java Normal file
View File

@ -0,0 +1,69 @@
public class Tri{
private Noeud racine;
public Tri(float f){
this.racine = new Noeud(f);
}
public void ajouterNoeud(float f){
if(this.racine.val>f){
if(this.racine.noeudGauche==null){
this.racine.addNoeudGauche(f);
}
else{
this.ajouterNoeud(f,this.racine.noeudGauche);
}
}
else{
if(this.racine.noeudDroit==null){
this.racine.addNoeudDroit(f);
}
else{
this.ajouterNoeud(f,this.racine.noeudDroit);
}
}
}
public void ajouterNoeud(float f, Noeud n){
if(n.val>f){
if(n.noeudGauche==null){
n.addNoeudGauche(f);
}
else{
this.ajouterNoeud(f,n.noeudGauche);
}
}
else{
if(n.noeudDroit==null){
n.addNoeudDroit(f);
}
else{
this.ajouterNoeud(f,n.noeudDroit);
}
}
}
@Override
public String toString(){
String retour = "";
if(this.racine.noeudGauche!=null){
retour = toString(this.racine.noeudGauche) + retour;
}
if(this.racine.noeudDroit!=null){
retour = retour + " " + toString(this.racine.noeudDroit);
}
return retour;
}
public String toString(Noeud n){
String retour = " "+n.val;
if(n.noeudGauche!=null){
retour = toString(n.noeudGauche) + retour;
}
if(n.noeudDroit!=null){
retour = retour + " " + toString(n.noeudDroit);
}
return retour;
}
}