提交时间:2024-08-19 20:53:52
运行 ID: 167934
#include <iostream> using namespace std; int part(int a[], int low, int high) { int t; int pi=a[high]; int i=(low-1); for (int j=low; j<=high-1; j++) { if (a[j] <= pi) { i++; t=a[i]; a[i]=a[j]; a[j]=t; } } t=a[i+1]; a[i+1]=a[high]; a[high]=t; return (i + 1); } void qSort(int a[], int low, int high) { if (low < high) { int pi = part(a, low, high); qSort(a, low, pi-1); qSort(a, pi+1, high); } } int main() { int a[100001],n; cin>>n; for(int i=0;i<n;i++) { cin>>a[i]; } qSort(a,0,n-1); for(int i=0;i<n;i++) { cout<<a[i]<<" "; } return 0; }