quick sort


 1 using  System;
 2 namespace  MyQSort {
 3 public class QSort //可以写成static public class QSort
 4 {
 5  private static int[] toBeSort;
 6  private static void swap(int a,int b){
 7   int c;
 8   c=toBeSort[a];
 9   toBeSort[a]=toBeSort[b];
10   toBeSort[b]=c;
11  }

12  /**////<sumary>
13  ///分割函数
14  ///</sumary>

15  private static int Partition(int low,int high){
16   int pivoKey=toBeSort[low];
17   while(low<high){
18    while(low<high && (toBeSort[high] >= pivoKey)) --high;
19    swap(low,high);
20    while(low<high && (toBeSort[low] <= pivoKey))  ++low;
21    swap(low,high);
22   }

23   return low;
24  }

25  private static void QQSort(int low,int high){
26   int pivoLoc;
27   if(low<high){
28    pivoLoc=Partition(low,high);
29    QQSort(low,pivoLoc-1);
30    QQSort(pivoLoc+1,high);
31   }

32  }

33  public static int[] QuickSort(int [] a){
34   toBeSort=a;
35   QQSort(0,toBeSort.Length-1);
36   return toBeSort;
37  }

38
39 }
;
40}

41

转载于:https://www.cnblogs.com/xiaotao823/archive/2008/01/28/1055394.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值