java数据结构和算法------合并排序

 
 package iYou.neugle.sort;

 public class Merge_sort {

     public static void MergeSort(double[] array, int start, int end) {
if (start < end) {
int middle = (start + end) / 2;
MergeSort(array, start, middle);
MergeSort(array, middle + 1, end);
Merge(array, start, middle, end);
}
} private static void Merge(double[] array, int start, int middle, int end) {
int n1 = middle - start + 1;
int n2 = end - middle;
double[] L = new double[n1];
double[] R = new double[n2];
for (int i = 0; i < n1; i++) {
L[i] = array[start + i];
}
for (int i = 0; i < n2; i++) {
R[i] = array[middle + i + 1];
}
for (int i = 0, j = 0, k = start; k <= end; k++) {
if (j == n2 || (i < n1 && L[i] <= R[j])) {
array[k] = L[i];
i++;
} else {
array[k] = R[j];
j++;
}
}
}
}
上一篇:解决EP拒绝访问注册表Global键的的问题


下一篇:python的logging模块