希尔排序
来源:互联网 发布:海文考研怎么样知乎 编辑:程序博客网 时间:2024/06/06 00:17
希尔排序的思想:首先把排序分为若干个序列进行直接插入排序,等记录中的数基本有序再进行一次直接插入排序。
package chengxu;
public class shellSort {
public static void shellSort(int[] numbers){
int len=numbers.length;
int temp=0;
int j=0;
for(int crement=len/2;crement>0;crement/=2)
{
for(int i=crement;i<len;i++)
{
temp=numbers[i];
for(j=i;j>=crement;j-=crement)
{
if(temp<numbers[j-crement])
{
numbers[j]=numbers[j-crement];
}else{
break;
}
}
numbers[j]=temp;
}
}
}
public static void printArr(int[] numbers){
for(int i = 0 ; i < numbers.length ; i ++ )
{
System.out.print(numbers[i] + ",");
}
System.out.println("");
}
public static void main(String[] args) {
int[] numbers = {10,20,15,0,6,7,2,1,-5,55};
System.out.print("排序前:");
printArr(numbers);
shellSort(numbers);
System.out.print("快速排序后:");
printArr(numbers);
}
}
阅读全文
0 0
- 希尔排序
- 希尔排序
- 希尔排序
- 希尔排序
- 希尔排序
- 希尔排序
- 希尔排序
- 希尔排序
- 希尔排序
- 希尔排序
- 希尔排序
- 希尔排序
- 希尔排序
- 希尔排序
- 希尔排序
- 希尔排序
- 希尔排序
- 希尔排序
- 解决:Connections could not be acquired from the underlying database!
- Gallery画廊
- 微信小程序开发-新闻列表之新闻列表绑定
- 浅谈学习
- 全部SAP转储订单(STO)
- 希尔排序
- 使用flowable 6.1.2 REST API 运行请假审批流程
- ajax 技术总结
- SDUT-约瑟夫问题
- fiddler本地代理替换js文件
- mac mysql启动不了 Can 't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock '(2)
- Android Studio 写代码特效 编译器代码特效 以及小地图
- MongoDB 使用教程--基本增删改查语法
- [Python] 生成200个激活码(优惠券)