快速排序
#include<iostream>
using namespace std;
int partition(int arr[],int low,int high)
{
int pivot=arr[high];//选择基准
int i=low-1;
for(int j=low;j<high;j++)
{
if(arr[j]<pivot)
{
i++;
swap(arr[i],arr[j]);
}
}
swap(arr[i+1],arr[high]);
return i+1;
}
void quicksort(int arr[],int low,int high)
{
if(low<high)
{
int a=partition(arr,low,high);
quicksort(arr,low,a-1);
quicksort(arr,a+1,high);
}
}
int main()
{
int n;
cin>>n;
int arr[n];
for(int i=0;i<n;i++)
{
cin>>arr[i];
}
quicksort(arr,0,n-1);
for(int i=0;i<n;i++)
{
cout<<arr[i]<<" ";
}
}