希尔排序
2016-04-24 12:55
337 查看
package sun; public class Sort { /** * * @param 待排序数组 * */ public static void shell(int[] a, int l, int r) { int h; for (h = l; h <= (r - l) / 9; h = 3 * h + 1); for (; h > 0; h /= 3) { for (int i = l + h; i <= r; i++) { int j = i; int v = a[i]; while (j >= l + h && v < a[j - h]) { a[j] = a[j - h]; j -= h; } a[j] = v; } } } public static void main(String[] args) { int[] arr = { 49, 38, 65, 97, 76, 13, 27, 49 }; shell(arr, 0, arr.length - 1); for (int a : arr) System.out.println(a); } }
相关文章推荐
- 使用ajax实现用户登录验证(升级版)
- 谈谈布隆过滤器(比哈希表省很多内存,简言之更牛逼)
- hibernate ——helloWorld程序(XML配置)
- css
- 手把手教你使用Git
- 门户网站CDN+Nginx+Javaee应用服务器集成项目实施过程
- poj 1952buy low, buy lower
- Guava类库学习--Multiset+Multimap+BiMap
- Greatest Common Divisor (GCD) - Euclidean algorithm
- 翻转单词顺序VS左旋转字符串
- Common Multiple and Least Common Multiple(LCM)
- 【Http专题】基础
- PHP 运算符
- 【动态规划】XMU 1560 新ACM规则
- zoj3946 Highway Project
- mysql 时间
- A+B和C,PAT 1011
- Android OkHttp完全解析 是时候来了解OkHttp了
- 一、 单例设计模式
- cocos2d-x中Texture2D::TexParams(图片平铺)一张图片铺满全屏做背景