提交时间:2024-08-19 22:14:00
运行 ID: 168076
#include <bits/stdc++.h> using namespace std; int partion(int a[],int low,int high) { int p = a[high]; int k = low-1; for (int i=low;i<high;i++) { if(a[i]<p) { swap(a[i],a[++k]); } } swap(a[high],a[++k]); return k; } void QuickSort(int a[],int low,int high) { if (low>=high) return; int center; center = partion(a,low,high); QuickSort(a,low,center-1); QuickSort(a,center+1,high); } int main() { int n; cin >> n ; int a[n]; for (int i=0;i<n;i++) { cin >> a[i]; } QuickSort(a,0,n-1); for (int j=0;j<n;j++) { cout << a[j] <<" "; } return 0; }