1 #include<iostream>
 2 using namespace std;
 3 
 4 
 5 
 6 int Partition(int a[],int p,int r,int q)//实现划分
 7 {
 8     int x = a[r];
 9     int i = p - 1;
10     for (int j = p; j <= r - 1; j++)
11         if (a[j] <= x)
12         {
13             i++;
14             int t = a[i];
15             a[i] = a[j];
16             a[j] = t;
17         }
18     {
19         int t = a[i + 1];
20         a[i + 1] = a[r];
21         a[r] = t;
22     }
23     q = i + 1;
24     return q;
25 }
26 
27 
28 
29 void Quicksort(int a[], int p, int r)
30 {
31     int q=p;
32     if (p < r)
33     {
34         q=Partition(a, p, r, q);
35         Quicksort(a, p, q - 1);
36         Quicksort(a, q + 1, r);
37     }
38 }
39 
40 
41 void main()
42 {
43     int a[11];
44     for (int i = 1; i < 11; i++)
45         a[i] = 11 - i;
46     Quicksort(a, 1, 10);
47     for (int i = 1; i < 11; i++)
48         cout << a[i] << endl;
49 }

 

 

posted on 2017-02-28 16:10  郑哲  阅读(120)  评论(0编辑  收藏  举报