Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/361.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 合并排序与插入排序的组合_Java_Sorting_Mergesort_Insertion Sort - Fatal编程技术网

Java 合并排序与插入排序的组合

Java 合并排序与插入排序的组合,java,sorting,mergesort,insertion-sort,Java,Sorting,Mergesort,Insertion Sort,有人能告诉我为什么在插入中阈值设置为时该代码不能正常工作吗?for循环不应该是 for (int i = n+1; i < b; i++){ merge()还需要一个修复,第一个while循环的尾随大括号需要在代码标记剩余序列之前上移: while(i<q && j<r){ if(f[i]<=f[j]){ temp[t] =f[i]; i++; t+

有人能告诉我为什么在插入中阈值设置为时该代码不能正常工作吗?for循环不应该是

    for (int i = n+1; i < b; i++){
merge()还需要一个修复,第一个while循环的尾随大括号需要在代码标记剩余序列之前上移:

    while(i<q && j<r){
        if(f[i]<=f[j]){
            temp[t] =f[i]; 
            i++;
            t++;
        }else{
            temp[t] = f[j];
            j++;
            t++;
        }
    }
    while(i<q){
        temp[t] = f[i];
        i++;
        t++;
    }
    while(j<r){
        temp[t]=f[j];
        j++;
        t++;
    }
当(iIf insertion_srt()根据您的指令进行更改时,输出的排序就更少了。输入:{20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1}输出:{11,19,20,18,15,13,9,10,8,6,5,5,4,3,2,1}
        while ((j > n) && (array[j-1] > B)){
    while(i<q && j<r){
        if(f[i]<=f[j]){
            temp[t] =f[i]; 
            i++;
            t++;
        }else{
            temp[t] = f[j];
            j++;
            t++;
        }
    }
    while(i<q){
        temp[t] = f[i];
        i++;
        t++;
    }
    while(j<r){
        temp[t]=f[j];
        j++;
        t++;
    }