合并2个未排序数组的排序

时间:2011-02-05 00:44:56

标签: java sorting

以下实现是否适用于合并排序?

public int [] merge_srt(int [] ary){
        if(ary.length==1)
            return ary;
        int mid = (int)ary.length/2;
        int a1[] =  merge_srt(Arrays.copyOfRange(ary, 0, mid));
        int a2[] = merge_srt(Arrays.copyOfRange(ary, mid+1,  ary.length-1));
        return mergeA(a1,a2);

    }

    public  int[]  mergeA(int[] a1,int [] a2){

        // merge 2 array and reurn one sorted array

    }

1 个答案:

答案 0 :(得分:1)

更改

    if (ary.length == 1)            
       return ary; 

    if (ary.length <= 1)            
       return ary;