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
Sorting 排序算法的类型_Sorting - Fatal编程技术网

Sorting 排序算法的类型

Sorting 排序算法的类型,sorting,Sorting,这是什么类型的排序算法: private static void Sort(int[] array) { int a=0,b=0; for (int j = 1; j < array.length; j++) { int index = array[j]; int previouse_index = j-1; while ( (previouse_index >= 0 ) && ( array [previo

这是什么类型的排序算法:

private static void Sort(int[] array) {
   int a=0,b=0;
   for (int j = 1; j < array.length; j++) {
        int index = array[j];
        int previouse_index = j-1;
        while ( (previouse_index >= 0 ) && ( array [previouse_index] < index ) ) 
        {
            array [previouse_index + 1] = array [previouse_index];
            previouse_index--;
            b++;
        }
        array[previouse_index+1] = index; 
        printNumbers(array);
        a++;
    }
    System.out.println("for loop iteration "+ a);
    System.out.println("while loop iteration "+ b);
}
私有静态无效排序(int[]数组){
int a=0,b=0;
对于(int j=1;j=0)和&(数组[上一个索引]

是泡泡型的吗?还是插入排序?或者完全不同的东西?

在删除无用代码、重命名变量并格式化后:

private static void Sort(int[] array) {
   for (int j = 1; j < array.length; j++) {
        int value = array[j];
        int index = j-1;
        while ( (index >= 0) && (array[index] < value) ) {
            array[index + 1] = array[index];
            index--;
        }
        array[index + 1] = value; 
    }
}
私有静态无效排序(int[]数组){
对于(int j=1;j=0)和&(数组[index]
现在很容易看到,在内部while循环中,数组中的大值上升(就像水中的气泡),因此它实际上是气泡排序算法的一个实现