标签:style blog http io ar color os sp for
1 #include <fstream> 2 #include <iostream> 3 #include <cstdio> 4 5 using namespace std; 6 7 const int nn=102; 8 int a[nn]; 9 10 int quick_partition(int i,int j); 11 void quick_sort(int s,int t); 12 13 int main() 14 { 15 //freopen("D:\\input.in","r",stdin); 16 //freopen("D:\\output.out","w",stdout); 17 int n; 18 scanf("%d",&n); 19 for(int i=1;i<=n;i++) scanf("%d",&a[i]); 20 quick_sort(1,n); 21 for(int i=1;i<=n;i++) printf("%d ",a[i]); 22 return 0; 23 } 24 int quick_partition(int i,int j) 25 { 26 a[0]=a[i]; 27 while(i<j) 28 { 29 while(i<j&&a[j]>=a[0]) j--; 30 if(i<j) a[i]=a[j],i++; 31 while(i<j&&a[i]<=a[0]) i++; 32 if(i<j) a[j]=a[i],j--; 33 } 34 a[i]=a[0]; 35 return i; 36 } 37 void quick_sort(int s,int t) 38 { 39 if(s<t) 40 { 41 int tmp=quick_partition(s,t); 42 quick_sort(s,tmp-1); 43 quick_sort(tmp+1,t); 44 } 45 }
标签:style blog http io ar color os sp for
原文地址:http://www.cnblogs.com/jiu0821/p/4138558.html