首页 > 其他 > 详细

快排算法实现

时间:2014-09-09 11:15:48      阅读:214      评论:0      收藏:0      [点我收藏+]
public class QuickSort {
    
    public static void sort(int arr[],int low,int high){
        int l=low;
        int h=high;
        int temp=arr[low];
        while(l<h)
        {
            while(l<h&&arr[h]>=temp) h--;
            arr[l]=arr[h];
            while(l<h&&arr[l]<=temp) l++;
            arr[h]=arr[l];
        }
        System.out.println("h:"+h+" l:"+l);
        arr[l]=temp;
        if(l>low)sort(arr,low,h-1);
        if(h<high)sort(arr,l+1,high);
    }
    
    public static void main(String[] args)
    {
        int a[]={5,8,7,1,3,2,6,4};
        sort(a,0,a.length-1);
        for(int i=0;i<a.length;i++)
            System.out.print(a[i]+" ");
    }

}

 

快排算法实现

原文:http://www.cnblogs.com/sunrunzhi/p/3961570.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!