controle machine
This commit is contained in:
39
DEV/DEV3.2/DEV32/1/Bulle.java
Normal file
39
DEV/DEV3.2/DEV32/1/Bulle.java
Normal file
@@ -0,0 +1,39 @@
|
||||
public class Bulle{
|
||||
|
||||
public static <E> boolean bulle(File<E> pileRemplis, File<E> pileVide){
|
||||
if (pileVide.isEmpty() == false){
|
||||
throw new IllegalArgumentException("Erreur : l'argument pileVide n'est pas vide");
|
||||
}
|
||||
|
||||
E max, v2;
|
||||
boolean haveChangement = false;
|
||||
if (pileRemplis.isEmpty() == false){
|
||||
max = pileRemplis.dequeue();
|
||||
while (pileRemplis.isEmpty() == false){
|
||||
v2 = max;
|
||||
max = pileRemplis.dequeue();
|
||||
if (max < v2){ // changer cette ligne pour rendre les objet comparable
|
||||
pileVide.enqueue(max);
|
||||
max = v2;
|
||||
haveChangement = true;
|
||||
}
|
||||
else{
|
||||
pileVide.enqueue(v2);
|
||||
}
|
||||
}
|
||||
pileVide.enqueue(max);
|
||||
}
|
||||
return haveChangement;
|
||||
}
|
||||
|
||||
public static <E> File<E> tri(File<E> pile1){
|
||||
File<E> pile2 = new File<>();
|
||||
File<E> transition = null;
|
||||
while (Bulle.bulle(pile1, pile2)){
|
||||
transition = pile2;
|
||||
pile2 = pile1;
|
||||
pile1 = transition;
|
||||
}
|
||||
return pile2;
|
||||
}
|
||||
}
|
BIN
DEV/DEV3.2/DEV32/1/File.class
Normal file
BIN
DEV/DEV3.2/DEV32/1/File.class
Normal file
Binary file not shown.
22
DEV/DEV3.2/DEV32/1/File.java
Normal file
22
DEV/DEV3.2/DEV32/1/File.java
Normal file
@@ -0,0 +1,22 @@
|
||||
import java.util.*;
|
||||
|
||||
public class File<E>{
|
||||
|
||||
private Queue<E> file;
|
||||
|
||||
public File(){
|
||||
this.file = new LinkedList<>();
|
||||
}
|
||||
|
||||
public void enqueue(E valeur){
|
||||
this.file.offer(valeur);
|
||||
}
|
||||
|
||||
public E dequeue(){
|
||||
return this.file.poll();
|
||||
}
|
||||
|
||||
public boolean isEmpty(){
|
||||
return this.file.isEmpty();
|
||||
}
|
||||
}
|
BIN
DEV/DEV3.2/DEV32/1/Main.class
Normal file
BIN
DEV/DEV3.2/DEV32/1/Main.class
Normal file
Binary file not shown.
43
DEV/DEV3.2/DEV32/1/Main.java
Normal file
43
DEV/DEV3.2/DEV32/1/Main.java
Normal file
@@ -0,0 +1,43 @@
|
||||
public class Main{
|
||||
public static void main(String[] args){
|
||||
int[] tableauEntier = new int[args.length];
|
||||
int i;
|
||||
try{
|
||||
//convertion en int
|
||||
for (i=0; i<args.length; i++){
|
||||
tableauEntier[i] = Integer.parseInt(args[i]);
|
||||
if (tableauEntier[i] < 0){
|
||||
throw new NumberFormatException("Erreur : l'entier naturel saisis est negatif "+tableauEntier[i]);
|
||||
}
|
||||
}
|
||||
|
||||
//remplissage
|
||||
File<Integer> fileRemplisBulle = new File<>();
|
||||
File<Integer> fileRemplisTri = new File<>();
|
||||
File<Integer> fileVide = new File<>();
|
||||
for (int entier : tableauEntier){
|
||||
fileRemplisBulle.enqueue(entier);
|
||||
fileRemplisTri.enqueue(entier);
|
||||
}
|
||||
|
||||
// methode bulle
|
||||
Bulle.bulle(fileRemplisBulle, fileVide);
|
||||
System.out.print("Bulle : ");
|
||||
while (fileVide.isEmpty() == false){
|
||||
System.out.print(fileVide.dequeue() + " ");
|
||||
}
|
||||
System.out.println();
|
||||
|
||||
//methode tri
|
||||
Bulle.tri(fileRemplisTri);
|
||||
System.out.print("Tri : ");
|
||||
while (fileRemplisTri.isEmpty() == false){
|
||||
System.out.print(fileRemplisTri.dequeue() + " ");
|
||||
}
|
||||
System.out.println();
|
||||
}
|
||||
catch(NumberFormatException e){
|
||||
System.out.println("argument invalide");
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user