大佬救命
,归并排序,怎么结果还差一点
运行结果在图片上
package test;import kotlin.jvm.functions.Function1;
import java.util.Arrays;
public class project{
public static void main(String[] args){
int[] arr2={45,56,41,15,48,25,26,58}; Func1(arr2,0, arr2.length-1); System.out.println(Arrays.toString(arr2)); } public static void Func1(int[] a,int left,int right) { if (left >= right)
return;
int mid=(left+right)/2;
Func1(a,left,mid);
Func1(a,mid+1,right); twoSort(a,left,mid,right); }
public static void twoSort(int[] arr,int a,int b,int c)
{ int n1=b+1-a,n2=c-b;
int[] str1=new int[n1+1];
int[] str2=new int[n2+1];
for (int i = 0; i < n1; i++)
str1[i]=arr[a+i];
for (int i = 0; i < n2; i++)
str2[i]=arr[b+1+i]; str1[n1]=Integer.MAX_VALUE; str2[n2]=Integer.MAX_VALUE;
int i=0,j=0;
for (int k=a;k<=c-a;k++)
{ if(str1[i]>=str2[j])
arr[k]=str2[j++];
else
arr[k]=str1[i++];} }}