1 基本思想

shell排序又称之为缩小增量排序,基本思想是,先将待排序序列分割成若干个特殊的子表,分别进行插入排序,当整个表中元素”基本有序”时,再对全体记录进行一次直接插入排序。该方法实质上是一个分组插入方法。

2,算法的实现(Java)

package Algorithm;

public class ShellSort {

    /**
* @param args
*/
public static void main(String[] args) {
int[] data = new int[] {11,10,55,78,100,111,45,56,79,90,345,1000};
System.out.println("排序之前:");
ShellSort.output(data);
System.out.println();
System.out.println("排序之后:");
ShellSort.Shell_Sort(data);
ShellSort.output(data);
} //带增量的插入排序
public static void Shell_Sort(int[] arr){
int s = 1;
while (s < arr.length)
s = s * 3 + 1;
while (s >= 1) {
for (int i = 1; i < arr.length; i++) {
for (int j = i; j >= s; j = j - s) {
if (arr[j] < arr[j - s]) {
int temp = arr[j];
arr[j]= arr[j-s];
arr[j-s] = temp;
} else{
break;
}
}
}
s = s / 3;
}
} //输出打印
public static void output(int[] arr){
for(int i=0;i<arr.length;i++){
System.out.print(arr[i]+"\t");
}
} }

最终结果显示如下:

3,性能分析

shell排序需要一个记录的辅助空间,它是一种不稳定的排序。

最新文章

  1. 几种linux脚本的简单执行方法
  2. ( 转)基于.NET平台常用的框架整理
  3. ACM学习之路————一个大整数与一个小整数不得不说得的秘密
  4. 【转】Mac OS X开机启动Path had bad permissions错误解决方案
  5. ORACLE 如何定位消耗资源的SQL
  6. mini2440移植uboot-2008.10 (一)
  7. Sed&amp;awk笔记之sed篇
  8. 最近国外很拉风的,,基于.net 的一个手表
  9. [Mugeda HTML5技术教程之9]使用元件
  10. Ansible之 Inventory 资源清单介绍
  11. DAY5-小别-2018-1-15
  12. 【Java学习笔记之二十】final关键字在Java继承中的用法小结
  13. 《玩转spring全家桶》学习笔记-------------丁雪丰
  14. 基于vue的图片查看插件vue-photo-preview
  15. Python全栈开发之路 【第十八篇】:Ajax技术
  16. orm操作
  17. Python3基础 dict clear 清空一个字典
  18. 【命令】MongoDB常用命令记录
  19. nigos core 安装配置
  20. vue实现点击区域外部的区域,关闭该区域

热门文章

  1. Mac CLion下OpenGL环境配置
  2. Perl面向对象(1):从代码复用开始
  3. linux学习基础1
  4. Ubuntu 安装 JDK8 的两种方式
  5. 数据库部分(MySql)_2
  6. [angularjs] angularjs系列笔记(八)事件
  7. [nodejs] nodejs开发个人博客(二)入口文件
  8. js 中prototype运用(数组)
  9. SQLite: sql script demo
  10. 洛谷P4725 【模板】多项式对数函数(多项式ln)