码迷,mamicode.com
首页 > 其他好文 > 详细

quicksort

时间:2014-08-04 08:17:56      阅读:204      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   io   ar   div   amp   log   

public void quicksort(int[] array, int low, int high){
        int i = low;
        int j = high;
        if(i>j)
            return;
        int pivot = i + (j-i)/2;
        int pnum = array[pivot];
        while(i<=j){
            // array[i] == pnum error. because have to be swap.
            while(i<=j && array[i]<pnum)
                i++;
            while(i<=j && array[j]>pnum)
                j--;
            if(i<=j){
            exchange(array,i,j);
            i++;
            j--;
            }
        }
          // Recursion
          quicksort(array,low, j);
          quicksort(array,i, high);
        
        
    }

 

quicksort,布布扣,bubuko.com

quicksort

标签:style   blog   color   io   ar   div   amp   log   

原文地址:http://www.cnblogs.com/leetcode/p/3889253.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!