45 lines
706 B
C++
45 lines
706 B
C++
#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 ; //当i变为left值,进入第一个递归,right变为0,此时return 结束此递归函数。
|
||
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 ;//此处return结束的是这个quicksort函数
|
||
|
||
}
|
||
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;
|
||
}
|