//将有序子序列合并成大序列void mergeSub(int *a, int start, int middle,int end){ //申请辅助空间 int len = end - start + 1; int *b = new int[len]; int i = start; int j = middle + 1; int k = 0; while (i<=middle && j<=end) { b[k++] = a[i] < a[j] ? a[i++] : a[j++]; } while (i<=middle) { b[k++] = a[i++]; } while (j<=end) { b[k++] = a[j++]; } for (int i = 0; i < len;i++) { a[start++] = b[i]; } delete[]b;}//归并排序--递归实现(自顶向下)void mergeSort(int *a, int start,int end){ int middle = (start + end) / 2; if (start==end) { return; } mergeSort(a, start, middle); mergeSort(a, middle + 1, end); mergeSub(a, start, middle, end);}//归并排序--迭代实现(自底向上)void mergeSortIterator(int *a, int start, int end){ int length = 1; //子序列的长度 while (length