public class ct {
public static void main(String args[]) {
array ARRAY = new array(args);
int[] b = new int[args.length];
for(int i=0; i<args.length; i++) {
b[i] = Integer.parseInt(args[i]);
}
ARRAY.mergesort(b);
ARRAY.out();
}
}class array {
int left;
int right;
int[] b;

array(String[] a) {
b = new int[a.length];
left = 0;
right = a.length - 1;
for(int i=0; i<a.length; i++) {
b[i] = Integer.parseInt(a[i]);
}
}

public void merge(int[] a,int[] b) {
int i = 0;
int j = 0;
int k = 0;
int[] catcher = new int[a.length + b.length];
while(j <= a.length  && k <= b.length) {
if(a[j] > b[k]) {
catcher[i++] = b[k++];
}
else if(a[j] < b[k]) {
catcher[i++] = a[j++];
}
}
if(j == a.length ) {
for(int I=k + 1; I< catcher.length; I++) {
catcher[i++] = b[I];
}
}
else if(k == b.length ){
for(int I=j + 1; I<catcher.length; I++) {
catcher[i++] = a[I];
}
}
}

public void out() {
System.out.println("排序的结果为:");
for(int i=0; i<catcher.length; i++) {
System.out.print(catcher[i] + " ");
}
}

public void mergesort(int[] B) {
left = 0;
right = B.length - 1;
int[] divided1;
int[] divided2;
if(B.length == 0) {
System.out.println("请先完成数组设置!");
}
if(B.length == 1) {
B[0] = B[0];
}
else {
divided1 = new int[(left + right + 2)/2];
divided2 = new int[B.length - ((left + right + 2)/2)];
for(int i=0; i<divided1.length; i++) {
divided1[i] = B[i];
}
int dd = 0;
for(int i=B.length-divided1.length+1; i<B.length; i++) {
divided2[dd++] = B[i];
}
mergesort(divided1);
mergesort(divided2);
merge(divided1,divided2);
}
}
}