以下实现是否适用于合并排序?
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
}
答案 0 :(得分:1)
更改
if (ary.length == 1)
return ary;
到
if (ary.length <= 1)
return ary;