You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
#include <iostream>
|
|
|
|
|
#include <cstdio>
|
|
|
|
|
using namespace std;
|
|
|
|
|
int a[101],n;
|
|
|
|
|
|
|
|
|
|
void quicksort(int left,int right) {
|
|
|
|
|
int i,j,t,tmp;
|
|
|
|
|
if(left>right)
|
|
|
|
|
return ; //<2F><>i<EFBFBD><69>Ϊleftֵ<74><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ݹ飬right<68><74>Ϊ0<CEAA><30><EFBFBD><EFBFBD>ʱreturn <20><><EFBFBD><EFBFBD><EFBFBD>˵ݹ麯<DDB9><E9BAAF><EFBFBD><EFBFBD>
|
|
|
|
|
tmp=a[left];
|
|
|
|
|
i=left;
|
|
|
|
|
j=right;
|
|
|
|
|
while(i!=j) {
|
|
|
|
|
while(a[j]>=tmp && i<j)
|
|
|
|
|
j--;
|
|
|
|
|
while(a[i]<=tmp && i<j)
|
|
|
|
|
i++;
|
|
|
|
|
if(i<j) {
|
|
|
|
|
t=a[i];
|
|
|
|
|
a[i]=a[j];
|
|
|
|
|
a[j]=t;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
a[left]=a[i];
|
|
|
|
|
a[i]=tmp;
|
|
|
|
|
|
|
|
|
|
quicksort(left,i-1);
|
|
|
|
|
quicksort(i+1,right);
|
|
|
|
|
return ;//<2F>˴<EFBFBD>return<72><6E><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>quicksort<72><74><EFBFBD><EFBFBD>
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
int main() {
|
|
|
|
|
int i,j;
|
|
|
|
|
cin>>n;
|
|
|
|
|
for(i=1; i<=n; i++) {
|
|
|
|
|
cin>>a[i];
|
|
|
|
|
}
|
|
|
|
|
quicksort(1,n);
|
|
|
|
|
for(i=1; i<=n; i++) {
|
|
|
|
|
cout<<a[i];
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|