希尔排序
来源:互联网 发布:济南网络推广招聘 编辑:程序博客网 时间:2024/05/29 18:36
package lsn1.sjjg.cct.cn.lsn1;import org.junit.Test;/** * 希尔排序 * Created by linyaokui on 17/12/8. */public class ShellSort { @Test public void test(){ int[] array=new int[]{3,9,1,2,5,4,7,8,6}; insertSort(array,2); for (int i : array){ System.out.print(i + " "); } System.out.println(" "); insertSort(array,1); for (int i : array){ System.out.print(i + " "); } } /** * 希尔排序 * * @param array 需要排序的数组 * @param step 步长 */ public void insertSort(int[] array, int step) { for (int k = 0; k < step; k++) { //对步长的定位,选择每次操作的开始位置 for (int i = k+step; i < array.length; i+=step) { int target = array[i]; // 要插入的目标数据 int j = i; // 如果j移动到0 或者发现比它小的就停止插入 while (j > step+k-1 && array[j - step] > target) { array[j] = array[j - step]; j-=step; } array[j] = target; //执行插入 } } }}
阅读全文
0 0
- 希尔排序
- 希尔排序
- 希尔排序
- 希尔排序
- 希尔排序
- 希尔排序
- 希尔排序
- 希尔排序
- 希尔排序
- 希尔排序
- 希尔排序
- 希尔排序
- 希尔排序
- 希尔排序
- 希尔排序
- 希尔排序
- 希尔排序
- 希尔排序
- LED驱动
- Eclipse快捷键
- Android自定义ViewGroup:实现简单的垂直方向线性布局(2)
- 项目中遇到的 蜜汁 VC 管理fang'an
- 《python机器学习及实践-从零开始通往kaggle竞赛之路(代码Python 3.6 版)》chapter1.1
- 希尔排序
- Ubuntu安装yaml
- LeetCode练习记录2017/12/8
- android7.1增加一个开机自启动的bin应用遇到的权限问题
- No mapping found for HTTP request with URI [/service/model/xxx/json] in DispatcherServlet
- 学习Maven日记-1
- Python 配置文件(.ini、 .conf、 .cfg)的读写
- jsp学习4-属性相关
- pytorch 0.3发布(0.3.0b0),更新信息以及更新步骤