码迷,mamicode.com
首页 > 系统相关 > 详细

ShellSort

时间:2016-09-09 23:53:23      阅读:217      评论:0      收藏:0      [点我收藏+]

标签:

code:

 1 @SuppressWarnings({ "rawtypes", "unchecked" })
 2 public static void shellSort(Object[] array) {
 3     int len = array.length;
 4     int h = 1;
 5     while (h <= len / 3)
 6         h = h * 3 + 1;
 7     while (h > 0) {
 8         for (int i = h; i < len; i++) {
 9             Comparable tmp = (Comparable) array[i];
10             int j = i;
11             while (j >= h && tmp.compareTo(array[j - h]) < 0) {
12                 array[j] = array[j - h];
13                 j -= h;
14             }
15             array[j] = tmp;
16         }
17         h = (h - 1) / 3;
18     }
19 }

 

ShellSort

标签:

原文地址:http://www.cnblogs.com/upside-down/p/5858361.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!