## 插入排序和希尔排序 原

sitaluoduoxi

``````public static void sortInsert(int[] datas){

int N = datas.length;
for (int i = 1; i < N; i++) {
int j = i;
if(datas[j] < datas[j-1]){
int temp = datas[j];
while( j > 0 && temp < datas[j-1]){
datas[j] = datas[j-1];
j --;
}
datas[j] = temp;
}
printArr(datas);
System.out.println();
}

}``````

``````public static void sortSheel(int[] datas){
int N = datas.length;
for (int gap = N /2; gap > 0;  gap /= 2) {
for(int i = gap; i< N; i++){
int temp = datas[i];
int j = i;
for( ; j >= gap &&  temp < datas[j - gap]; j -= gap){
datas[j] = datas[j-gap];
}
datas[j] = temp;
}
printArr(datas);
System.out.println();
}
}``````

60,78,2,7,5,87,34,46,23,123,32,53,45,9,99,88,65,[原数组]
23,78,2,7,5,9,34,46,60,123,32,53,45,87,99,88,65,[gap=8后结果]
5,9,2,7,23,78,32,46,45,87,34,53,60,123,99,88,65,[gap=4后结果]
2,7,5,9,23,46,32,53,34,78,45,87,60,88,65,123,99,[gap=2后结果]
2,5,7,9,23,32,34,45,46,53,60,65,78,87,88,99,123,[gap=1后结果]

© 著作权归作者所有

### sitaluoduoxi

Java数据结构与算法(六)-希尔排序

FantJ
2017/12/21
0
0

2017/05/18
0
0

2017/05/18
0
0

2017/05/18
0
0

2017/05/18
0
0

Bash 和 Python 编程语言优缺点分析

Bash 和 Python 是大多数自动化工程师最喜欢的编程语言。它们都各有优缺点，有时很难选择应该使用哪一个。所以，最诚实的答案是：这取决于任务、范围、背景和任务的复杂性。 让我们来比较一下...

xiangyunyan
30分钟前
4
0
Kubernetes从懵圈到熟练：读懂这一篇，集群节点不下线

35分钟前
10
0

https://blog.csdn.net/gem_yaorao/article/details/48626155

51分钟前
1
0
SpringBoot高级篇JdbcTemplate之数据更新与删除

3
0
Filecoin 编译问题

https://github.com/filecoin-project/go-filecoin/issues/2503 Error go run ./build build command from root I've faced on this error Building go-filecoin...git log -n 1 --forma......

2
0