55 lines
1.1 KiB
Java
55 lines
1.1 KiB
Java
|
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");
|
||
|
}
|
||
|
}
|
||
|
}
|