麻烦大佬看看哪有问题
import java.util.Arrays;
public class a {
public static void main(String[] args) {
int[] arr = {3, 6, 23, 7, 9, 4, 23, 67};
chai(arr, 0, arr.length - 1);
System.out.println(Arrays.toString(arr));
}
private static void chai(int[] arr, int startIndex, int endIndex) {
int centerIndex = (startIndex + endIndex) / 2;
if (startIndex<endIndex) {
chai(arr, startIndex, centerIndex);
chai(arr,centerIndex+1,endIndex);
guibin(arr,startIndex,centerIndex,endIndex);
}
}
private static void guibin(int[] arr, int startIdex, int centerIndex, int endIndex) {
int[] temparr = new int[endIndex - startIdex + 1];
int i = startIdex;
int j = centerIndex + 1;
int index = 0;
while (i<=centerIndex&&j<=endIndex){
if (arr[i]<=arr[j]){
temparr[index]=arr[i];
i++;
}else{
temparr[index]=arr[j];
j++;
}
index++;
}
while (i<=centerIndex){
temparr[index] = arr[i];
i++;
index++;
}
while (j<=centerIndex){
temparr[index] = arr[j];
j++;
index++;
}
for (int k = 0; k < temparr.length; k++) {
arr[k + startIdex] = temparr[k];
}
}
}