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_Binary_Insertion Sort - Fatal编程技术网

用于在Java中使用排序插入二进制进行反向操作

用于在Java中使用排序插入二进制进行反向操作,java,sorting,binary,insertion-sort,Java,Sorting,Binary,Insertion Sort,我正在编写一个二进制插入排序。代码如下: private static int[] sort(int[] a){ int x,m,L,R; for (int i=1;i<a.length;i++){ x = a[i]; L = 1; R = i; while (L < R){ m = (L + R) / 2; if (a[m] <= x){

我正在编写一个二进制插入排序。代码如下:

private static int[] sort(int[] a){
    int x,m,L,R;
    for (int i=1;i<a.length;i++){
        x = a[i];
        L = 1;
        R = i;
        while (L < R){
            m = (L + R) / 2;
            if (a[m] <= x){
                L = m + 1;
            } else {
                R = m;
            }
        }
        for (int j=i;j==R+1;j--){ //with i=5 and R=1 doesn't entry inside  
            a[j] = a[j-1];
        }
        a[R] = x;
    }
    return a;
}
私有静态int[]排序(int[]a){
int x,m,L,R;

对于(inti=1;iwell
j==R+1
在这种情况下是
false
,那么您为什么希望它进入循环?更容易了解它是如何实现的-