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.

45 lines
662 B

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#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;
}