# 归并排序-java

public static void main（String [] args）{
// TODO自动生成方法存根
int [] a = {1,4,7,2,5,8,3,6,9};

for（int i = 0; i <a.length; i ++）{//输出排序结果
System.out.print（a [i]）;
}

} private static void sort（int [] a）{ // TODO自动生成的方法存根int r = a.length - 1; int p = 0; merge_sort（A，P，R）; } private static void merge_sort（int [] a，int p，int r）{ // TODO自动生成的方法存根int q; 如果（r> p）{ q =（p + r）/ 2; merge_sort（A，P，Q）; merge_sort（A，Q + 1，R）; megre（A，P，Q，R）; } }

private static void megre（int [] a，int p，int q，int r）{
// TODO自动生成的方法存根
int [] L = new int [q-p + 1];
int [] R = new int [rq];
int n = 0;
int i = 0;
int j = 0;
for（int m = p; m <= q; m ++）{
L [n] = a [m];
N + = 1;
}
n = 0;
for（int m = q + 1; m <= r; m ++）{
R [n] = a [m];
N + = 1;
}
{try {
for（int k = p; k <= r; k ++）{
if（i <L.length && j <R.length && L [i] <= R [j]）{
a [k] = L [i]
I + = 1;
} else if（i <L.length && j <R.length && L [i]> R [j]）{
a [k] = R [j];
J + = 1;
} else if（i <L.length && j> = R.length）{
a [k] = L [i];
I + = 1;
} else if（i> = L.length && j <R.length）{
a [k] = R [j];
J + = 1;
}
}
} catch（ArrayIndexOutOfBoundsException e）{
System.out.println（“数组越界”）;
} } }