Loading... ``` #include <iostream> using namespace std; const int N = 1e5 + 10; int n, arr[N]; void sort(int left, int right) { if (left >= right) return ; int mid = ((right - left) >> 1) + left; sort(left,mid), sort(mid + 1, right); int l = left, r = mid + 1, temp[right - left + 1], idx = 0; while(l <= mid && r <= right) { if (arr[l] < arr[r]) temp[idx++] = arr[l++]; else temp[idx++] = arr[r++]; } while(l <= mid) temp[idx++] = arr[l++]; while(r <= right) temp[idx++] = arr[r++]; for (int i = left, idx = 0; i <= right; ++i) arr[i] = temp[idx++]; } int main () { ios::sync_with_stdio(0); cin.tie(0); cin >> n; for (int i = 0; i < n; ++i) cin >> arr[i]; sort(0, n - 1); for (int i = 0; i < n; ++i) cout << arr[i] << ' '; } ``` 最后修改:2024 年 08 月 08 日 © 允许规范转载 赞 如果觉得我的文章对你有用,请随意赞赏