当前位置:网站首页>Shell Sort
Shell Sort
2022-06-10 23:58:00 【Li_ XiaoJin】
Hill sort related content .
To pay off the debt , It took so long , Finally .
Hill's idea of sorting :https://lixj.fun/upload/2021/07/%E5%B8%8C%E5%B0%94%E6%8E%92%E5%BA%8F-3d0d7c36d19e49cdbc93487df55a28d3.mp4
Divide an array into several (h) A group ( General array length length/2), Then insert and sort each group separately . The number of arrays divided in each round is gradually reduced ,h/2->h/4->h/8, And sort it out , Keep order . When h=1 when , Then the array sorting is completed .
Algorithm complexity :O(nlog2n)
Algorithm space complexity :O(1)
Algorithm stability : Stable
public class ShellSort {
public static void sort(int[] arr) {
if (arr == null || arr.length < 2) {
return;
}
int length = arr.length;
int temp;
int gap = length / 2;
while (gap > 0) {
for (int i = gap; i < length; i++) {
temp = arr[i];
int preIndex = i - gap;
while (preIndex >= 0 && arr[preIndex] > temp) {
arr[preIndex + gap] = arr[preIndex];
preIndex -= gap;
}
arr[preIndex + gap] = temp;
}
gap /= 2;
}
}
public static void main(String[] args){
int[] arr = {10,7,2,4,7,62,3,4,2,1,8,9,19};
sort(arr);
System.out.println(Arrays.toString(arr));
}
}
Copyright: use Creative Commons signature 4.0 International license agreement to license Links:https://lixj.fun/archives/ Shell Sort
边栏推荐
- VS 番茄助手添加头注释 以及使用方式
- Solve access denied for user 'root' @ 'localhost' (using password: yes)
- Unity 脚本无法显示C#源码的中文注释 或者VS创建的脚本没有C#源码的注释
- LabVIEW get IMAQ get last event coordinates
- LabVIEW open other exe programs
- vtk. VTP download in JS
- What is the workflow of dry goods MapReduce?
- Kubernetes 基本介绍及核心组件
- Lambda learning records
- LabVIEW使用MathScript Node或MATLAB脚本时出现错误1046
猜你喜欢

【Pygame小游戏】来了来了它来了——这款五子棋小游戏超A的,分享给你的小伙伴儿一起pk吧~

Interface test learning notes

干货丨MapReduce的工作流程是怎样的?

LabVIEW确定控件在显示器坐标系中的位置

What is the workflow of dry goods MapReduce?

LabVIEW图片在从16位强制转换为8位后看起来要亮或暗

LabVIEW programming specification

判等问题:如何确定程序的判断是正确的?

【Pygame合集】滴~穿越童年游戏指南 请查收:这里面有你玩过的游戏嘛?(附五款源码自取)

LabVIEW获取Clamp函数找到的所有点的信息
随机推荐
Unity 脚本无法显示C#源码的中文注释 或者VS创建的脚本没有C#源码的注释
vtk. VTP download in JS
It is said that the verification code is a barrier in the crawler. I can break through it with only five lines of code.
【Pygame小游戏】不怕你走不过系列:极致AI走迷宫,学习完带你打开新世界大门~(附游戏源码)
Opencv实战之图像的基本操作:这效果出来惊艳了众人(附代码解析)
[opencv practice] this seal "artifact" is awesome, saving time and improving efficiency. It is powerful ~ (complete source code attached)
How to remove the blank at the top of listview
File转为MultipartFile的方法
上海网上开户是安全的吗?
LabVIEW displays the time and date on the waveform chart or waveform chart
【Pygame小游戏】这款“打地鼠”小游戏要火了(来来来)
Usage of C tryparse
C# Tryparse的用法
集合删除元素技巧 removeIf
Interview questions - written examination
【Pygame小游戏】激荡大脑思维,一起来玩转奇思妙想“24点”叭~(超赞滴)
Serial port missing in Ni Max in LabVIEW
LabVIEW 禁止其他可多核心处理的应用程序在所有核心上执行
LabVIEW调用DLL时出现异常0xc0000005代码
Mathematics and quality education