import java.util.Queue;
import java.util.ArrayDeque;
import java.awt.*; 

public class Main {


	private static <T extends Comparable<? super T>> ArrayDeque<T>[] scinder(ArrayDeque<T> file) {

		if (file == null) {
			return null;
		}

		ArrayDeque<T> file1 = new ArrayDeque<>();
		ArrayDeque<T> file2 = new ArrayDeque<>();
		int compteur = 0;
		while (!file.isEmpty()) {
			if (compteur % 2 == 0) {
				file1.addLast(file.removeFirst());
			} else {
				file2.addLast(file.removeFirst());
			}
			compteur++;
		}

		ArrayDeque<T>[] files = (ArrayDeque<T>[]) new ArrayDeque[2];
	    files[0] = file1;
	    files[1] = file2;
	    return files;
	} 


	private static <T extends Comparable<? super T>> ArrayDeque<T> fusionner(ArrayDeque<T> file1, ArrayDeque<T> file2) {
		ArrayDeque<T> fileFusionnee = new ArrayDeque<>();
		while (!file1.isEmpty() && !file2.isEmpty() && file1 != null && file2 != null) {
			T element1 = file1.peek();
			T element2 = file2.peek();

			if (element1.compareTo(element2) <= 0) {
				fileFusionnee.addLast(element1);
				file1.removeFirst();
			} else {
				fileFusionnee.addLast(element2);
				file2.removeFirst();
			}
		} 

		while (!file1.isEmpty() && file1 != null) {
			fileFusionnee.addLast(file1.removeFirst());
		}

		while (!file2.isEmpty() && file1 != null) {
			fileFusionnee.addLast(file2.removeFirst());
		}

		return fileFusionnee;
	}


	public static <T extends Comparable<? super T>> ArrayDeque<T> trier(ArrayDeque<T> file) {

		if (file.size() <= 1) {
			return file;
		}

		ArrayDeque<T>[] files = Main.scinder(file);
		ArrayDeque<T> file1 = Main.trier(files[0]);
		ArrayDeque<T> file2 = Main.trier(files[1]);
		return Main.fusionner(file1, file2);
	}

	public static void main(String[] args) {
		ArrayDeque<Double> file = new ArrayDeque<>();

		file.addLast(new Double(45.2D));
		file.addLast(new Double(-12.75D));
		file.addLast(new Double(89.0D));
		file.addLast(new Double(3.1415D));
		file.addLast(new Double(57.8D));
		file.addLast(new Double(0.0D));
		file.addLast(new Double(-45.6D));
		file.addLast(new Double(999.99D));
		file.addLast(new Double(48.547D));
		file.addLast(new Double(15.8D));

		file = Main.trier(file);

		System.out.print("[");
		for (Double nombre : file) {
			System.out.print(nombre + ", ");
		}
		System.out.println("]");
	}
}