提交时间:2024-08-19 23:49:57

运行 ID: 168191

#include <bits/stdc++.h> using namespace std; void Qsort(int arr[], int start, int end) { int lt = start, rt = end; if(start >= end) return ; int q = arr[start]; while(lt < rt) { while(rt > lt && arr[rt] >= q) rt--; while(lt < rt && arr[lt] <= q) lt++; swap(arr[lt], arr[rt]); } arr[start] = arr[lt]; arr[lt] = q; Qsort(arr, start, lt - 1); Qsort(arr, lt + 1, end); } int main() { int a[114514], n; cin >> n; for(int i = 1; i <= n; i++) cin >> a[i]; Qsort(a, 1, n); for(int i = 1; i <= n; i++) cout << a[i] << ' '; return 0; }