暴力解法快排
#include<iostream>
using namespace std;
void quick_sort(int a[],int n)
{
if(n<=1) return;
int find=a[0];
int small[n];
int big[n];
int small_count=0;
int big_count=0;
for(int i=1;i<n;i++)
{
if(a[i]<=find)
{
small[small_count]=a[i];
small_count++;
}
else
{
big[big_count]=a[i];
big_count++;
}
}
quick_sort(small,small_count);
quick_sort(big,big_count);
int begin=0;
for(int i=0;i<small_count;i++)
{
a[begin]=small[i];
begin++;
}
a[begin]=find;
begin=begin+1;
for(int i=0;i<big_count;i++)
{
a[begin]=big[i];
begin++;
}
}
int main()
{
int n=0;
cin>>n;
int a[n]={0};
for(int i=0;i<n;i++) cin>>a[i];
quick_sort(a,n);
for(int i=0;i<n;i++) cout<<a[i]<<" ";
return 0;
}