As Easy As A+B

http://acm.hdu.edu.cn/showproblem.php?pid=1040

View Code
 1 #include<stdio.h>
 2 int r[10000] ;
 3 int  QuickSort1 (int r[], int low, int high)
 4 {
 5     int  key;
 6     key=r[low];
 7     while(low<high)
 8       {
 9 
10           while(low<high && r[high]>=key) high--;
11           r[low]=r[high];
12           while (low<high && r[low]<=key) low++;
13           r[high]=r[low];
14     }
15     r[low]=key;
16     return low;
17 }
18 void  QuickSort(int  r[], int low, int high)
19 {
20     int k;
21     if(low<high)
22     {
23         k= QuickSort1 (r,low,high);
24         QuickSort (r,low,k-1);
25         QuickSort (r,k+1,high);
26     }
27 }
28 int main()
29 {
30     int n,  i, T  ;
31     int  QuickSort1 (int r[], int low, int high) ;
32     void  QuickSort(int  r[], int low, int high) ;
33     scanf("%d", &T) ;
34     while(T--)
35     {
36         scanf("%d", &n);
37         for(i=0; i<n; i++)
38         {
39            scanf("%d", &r[i]) ;
40         }
41 
42         QuickSort(r, 0, n-1) ;
43         printf("%d", r[0]) ;
44         for(i=1; i<n; i++)
45         {
46             printf(" %d", r[i]) ;
47         }
48         printf("\n") ;
49     }
50     return 0 ;
51 }

 

 

posted @ 2013-01-28 18:52  yelan@yelan  阅读(425)  评论(0编辑  收藏  举报