posts - 20,  comments - 6,  trackbacks - 0
 1 int Partition (Type a[], int p, int r)
 2 {
 3         int i = p, j = r + 1;
 4         Type x=a[p];
 5         // 将< x的元素交换到左边区域
 6         // 将> x的元素交换到右边区域
 7         while (true) {
 8            while (a[++i] <x);
 9            while (a[- -j] >x);
10            if (i >= j) break;
11            Swap(a[i], a[j]);
12            }
13        a[p] = a[j];
14        a[j] = x;
15        return j;
16 }
17 void QuickSort (Type a[], int p, int r)
18 {
19       if (p<r) {
20         int q=Partition(a,p,r);
21         QuickSort (a,p,q-1); //对左半段排序
22         QuickSort (a,q+1,r); //对右半段排序
23         }
24 

posted on 2009-02-06 22:44 混沌的云 阅读(330) 评论(0)  编辑 收藏 引用

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


<2009年2月>
25262728293031
1234567
891011121314
15161718192021
22232425262728
1234567

常用链接

留言簿(1)

随笔档案

搜索

  •  

最新评论

阅读排行榜

评论排行榜