排序算法总结

public static void quickSort(int[] arr,int begin,int end){
        if(begin>=end) return; //不可缺少???   递归的结束条件
        int idx=partion(arr,begin,end);
        quickSort(arr,begin,idx-1);
        quickSort(arr,idx+1,end);
    }
    private static int partion(int[] arr,int lo,int hi){
        int key=arr[lo];
        while(lo=key&&lo0&&arr[i]>key){
                arr[i+1]=arr[i];
                i--;
            }
            arr[i+1]=key;
            
        }
    }
    
    public static void MergeSort(int[] arr,int low,int high){
        int mid=low+(high-low)/2;
        MergeSort(arr,low,mid);
        MergeSort(arr,mid+1,high);
        Merge(arr,low,mid,high);
    }
    private static void Merge(int[] arr,int low,int mid,int high){
        int[] temp=new int[high-low+1];
        int i=low;
        int j=mid+1;
        int k=0;
        while(i

你可能感兴趣的:(排序算法总结)