提交时间:2024-08-19 19:01:54
运行 ID: 167830
#include <iostream> using namespace std; void QuickSort(int a[],int low,int high) { if (low>=high) return; int i=low; int j=high; int key=a[low]; while(i<j) { while(i<j&&key<a[j]) j--; a[i] = a[j]; while(i<j&&key>a[i]) i++; a[j] = a[i]; } a[i] = key; QuickSort(a,low,i-1); QuickSort(a,i+1,high); } int main() { int n; cin >> n ; int a[n]; for (int i=1;i<=n;i++) { cin >> a[i]; } QuickSort(a,0,n-1); for (int j=1;j<=n-2;j++) { cout << a[j] <<" "; } return 0; }