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循环中,数组中的大值上升(就像水中的气泡),因此它实际上是气泡排序算法的一个实现