class Main {
public static void main(String[] args) {
int[] arr = {1, 3, 4, 8, 2, 5, 6, 7};
merge(arr, 2, 4, 5 );
}
static void merge(int[] arr, int leftP, int rightP, int rightBound){
int[] temp = new int[rightBound - leftP + 1];
int k = 0;
int i = leftP;
int j = rightBound;
while ( i < rightP && j < rightBound ){
temp[k++] = arr[i] <= arr[j] ? arr[i++] : arr[j++];
}
while ( i < rightP ) temp[k++] = arr[i++];
while ( j < rightBound ) temp[k++] = arr[j++];
print(temp);
}
static void print(int[] arr){
System.out.println("输出数组:\n");
for ( int i = 0; i < arr.length; i++){
System.out.print(arr[i] + " ");
}
}
}