简单实现快速排序

package com.chenyilei.算法;

import java.util.Arrays;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * 注释
 *
 * @author chenyilei
 * @email [email protected]
 * @date 2019/06/17 8:42
 */
public class QuickSort {

    static Integer [] array = {10,5,6,9,8,1,4,2,3,7};
    static AtomicInteger count =new AtomicInteger(0);

    public static int doPart(int start,int end){
        int i = start;
        int j = end;
        int val = array[start];

        while (i < j){
            while (i<j){
                if(array[j] < val){
                    array[i] = array[j];
                    break;
                }
                j--;
            }
            while (i<j){
                if(array[i] > val){
                    array[j] = array[i];
                    break;
                }
                i++;
            }
            array[i] = val;
        }
        return i;
    }

    public static void quickSort(int start,int end){
        if(start < end){
            int part = doPart(start, end);
            quickSort(start,part-1);
            quickSort(part+1,end);

            count.incrementAndGet();
        }
    }

    public static void main(String[] args) {
        quickSort(0,array.length-1);
        System.out.println(Arrays.asList(array));
        System.out.println(count.get());
    }

}

你可能感兴趣的:(J2EE实用技术,java,快速排序,快排,算法)