Package chap02; import static org. junit. assert. *; import java. util. arrays; import java. util. random; import org. junit. test; /***** insert and sort small arrays in Merge Sorting ** @ author xiaojintao **/public class ques2_1 {/*** Merge Sorting Algorithm ** @ param *@ return */static void mergeSortWithInsertSort (int [], int start, int end, int k) {if (start <end-1) {insertSort (a, start, end); System. out. println ("diaoyongle");} int mid = (start + end)/2; mergeSortWithInsertSort (a, start, mid, k); mergeSortWithInsertSort (a, mid, end, k); merge (a, start, mid, end );}} /*** merge two sorted sequences ** @ param a * @ param B * @ return */protected static void merge (int [] n, int start, int mid, int end) {int [] l = Arrays. copyOfRange (n, start, mid); int [] r = Arrays. copyOfRange (n, mid, end); int I = 0; int j = 0; // j <mid-start int k = 0; // k <end-mid while (I <end-start) {if (j <mid-start & k <end-mid) {if (l [j] <r [k]) {n [I + start] = l [j]; j ++ ;} else {n [I + start] = r [k]; k ++ ;}} else if (k <end-mid) {n [I + start] = r [k]; k ++;} else if (j <mid-start) {n [I + start] = l [j]; j ++;} I ++;} // System. out. println (Arrays. toString (n);}/*** Insert the Sorting Algorithm, from start to end in the sequence (excluding end) insert sequence between start <end ** @ param n * @ return */static void insertSort (int [] n, int start, int end) {for (int j = start + 1; j <end; j ++) {int k = n [j]; int I = j-1; while (n [I]> k) {n [I + 1] = n [I]; I --; if (I = start-1) break ;} n [I + 1] = k ;}}}