voidmergeSort(vector<int>& arr, int L, int M, int R){ vector<int> help(R - L + 1); // L,R 范围的辅助空间 int i = 0; int p1 = L; int p2 = M + 1; while (p1 <= M && p2 <= R) { // p1 p2 都没越界,谁小就拷贝到 help help[i++] = arr[p1] <= arr[p2] ? arr[p1++] : arr[p2++]; } while (p1 <= M) { help[i++] = arr[p1++]; } while (p2 <= R) { help[i++] = arr[p2++]; } for (i = 0; i < help.size(); ++i) { arr[L + i] = help[i]; } }