希尔排序
来源:互联网 发布:snmp及编程实现 编辑:程序博客网 时间:2024/06/06 16:56
package sort1;public class ShellSort { /** * 希尔排序的一趟插入 * @param arr 待排数组 * @param d 增量 */ public static void shellInsert(int[] arr, int d) { for(int i=d; i<arr.length; i++) { int j = i - d; int temp = arr[i]; //记录要插入的数据 while (j>=0 && arr[j]>temp) { //从后向前,找到比其小的数的位置 arr[j+d] = arr[j]; //向后挪动 j -= d; } if (j != i - d) //存在比其小的数 arr[j+d] = temp; } } public static void shellSort(int[] arr) { if(arr == null || arr.length == 0) return ; int d = arr.length >>2; while(d >= 1) { shellInsert(arr, d); d /= 2; } } public static void main(String[] args) {int a[]={5,7,4,3,1,6};shellSort(a);for(int i:a){System.out.print(i+" ");}}}
0 0
- 希尔排序
- 希尔排序
- 希尔排序
- 希尔排序
- 希尔排序
- 希尔排序
- 希尔排序
- 希尔排序
- 希尔排序
- 希尔排序
- 希尔排序
- 希尔排序
- 希尔排序
- 希尔排序
- 希尔排序
- 希尔排序
- 希尔排序
- 希尔排序
- UVALive 7500 Boxes and Balls (二分)
- Java8之Lambda表达式
- CSS样式
- 图像去模糊(逆滤波)
- 首页 干货教程 大数据动向 大数据应用 数据可视化 数据分析 投资并购 企业专区 注册 登录 随机森林入门攻略(内含R、Python代码)
- 希尔排序
- 【OpenCV】颜色空间(RGB,HSV与Gray)及图像处理中的颜色识别
- DCI format 5A相关学习
- 21. Merge Two Sorted Lists leetcode(lists)
- Retrofit开发指南
- 一个Android程序员的第一年
- Python3在Windows安装配置及简单试用
- 二叉树的实例化
- 享元模式