62 lines
1.5 KiB
Java
62 lines
1.5 KiB
Java
import java.util.*;
|
|
|
|
public class Main {
|
|
|
|
public static ArrayDeque<Float> scinder(ArrayDeque<Float> file) {
|
|
ArrayDeque<Float> nouveaufile = new ArrayDeque<>();
|
|
|
|
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) {
|
|
ArrayDeque<Float> fusionnee = new ArrayDeque<>();
|
|
|
|
while (!fileun.isEmpty() && !filedeux.isEmpty()) {
|
|
if (fileun.peek() <= filedeux.peek()) {
|
|
fusionnee.add(fileun.poll());
|
|
} else {
|
|
fusionnee.add(filedeux.poll());
|
|
}
|
|
}
|
|
|
|
fusionnee.addAll(fileun);
|
|
fusionnee.addAll(filedeux);
|
|
|
|
return fusionnee;
|
|
}
|
|
|
|
public static ArrayDeque<Float> trier(ArrayDeque<Float> file) {
|
|
if (file.size() <= 1) {
|
|
return file;
|
|
}
|
|
|
|
ArrayDeque<Float> fileun = scinder(file);
|
|
ArrayDeque<Float> filedeux = new ArrayDeque<>(file);
|
|
|
|
filedeux.removeAll(fileun);
|
|
|
|
fileun = trier(fileun);
|
|
filedeux = trier(filedeux);
|
|
|
|
return fusionner(fileun, filedeux);
|
|
}
|
|
|
|
public static void main(String[] args) {
|
|
ArrayDeque<Float> file = new ArrayDeque<>();
|
|
|
|
for (String arg : args) {
|
|
file.add(Float.parseFloat(arg));
|
|
}
|
|
|
|
file = trier(file);
|
|
|
|
for (Float f : file) {
|
|
System.out.println(f);
|
|
}
|
|
}
|
|
}
|