当前位置:网站首页>Direct insertion sort - [common sort method (1/8)]
Direct insertion sort - [common sort method (1/8)]
2022-06-23 05:07:00 【Dongguan hehe】
Catalog
1、 Ideas
1、 We regard the first number as an order , Then there is the unordered region
2、 from 1 The subscripts are compared with the previous ordered parts in turn , Stop until it is less than the element or the comparison has been completed
3、 Insert the element to the stop position
2、 demonstration

3、 attribute
1、 Time complexity
It is best to O(n) The sequence of numbers to be arranged has been orderly .
The worst is O(n^2) Sequence to be arranged in reverse order
2、 Spatial complexity
The space complexity is O(1), No new series created
3、 stability
Stable
4、 Original code
public class TestDemo1 {
public static void insertSort(int[] nums){
for (int i = 1; i < nums.length; i++) {
int tmp=nums[i];
int j = i - 1;
for (; j >= 0 ; j--) {
if(nums[j]>tmp){// If you add the equal sign, it becomes unstable
nums[j+1]=nums[j];
}else{
break;
}
}
nums[j+1]=tmp;
}
}
public static void main(String[] args) {
int[] nums={23,6,5,34,38,3,32,48};
insertSort(nums);
System.out.println(Arrays.toString(nums));
}
}
边栏推荐
- How to solve multi-channel customer communication problems in independent stations? This cross-border e-commerce plug-in must be known!
- Notepad++ find replace group replace retain
- Course design C for freshmen -- clothing management system
- WPF 基础控件之 TabControl样式
- How can mushrooms survive a five-year loss of 4.2 billion yuan?
- Abnova liquidcell negative enrichment cell separation and recovery system
- Abnova fluorescent dye 555-c3 maleimide scheme
- Mini Homer - can you get a remote map data transmission link for hundreds of yuan?
- This markdown artifact will be charged!
- 8年经验之谈:月薪3000到30000,测试工程师的变“行”记
猜你喜欢

入行软件测试5年,跳槽3次,我摸透了软件测试这一行

go学习记录二(Window)

Usage of apipost interface test ------ get

GNSS速度解算的三种方法

Less than a year after development, I dared to ask for 20k in the interview, but I didn't even want to give 8K after the interview~

Architecture à trois niveaux MVC

Abnova actn4 purified rabbit polyclonal antibody instructions

Arduino温湿度传感器DHT11(含代码)
![[C language] keyword](/img/76/fa0a8aa496ef6ff704d9c417e4b37c.png)
[C language] keyword

Official download and installation of QT and QT vs tools plug-ins
随机推荐
3 天完成小学期项目,手把手教你完成天气播报系统!
ICer技能01正则匹配
云原生数据库如荼如火,未来可期
Abnova actn4 purified rabbit polyclonal antibody instructions
滑块视图的实现
rtklib2.4.3 b34 单点定位的一个bug
centos7安装postgresql8.2.15及存储过程创建
Seven year manong Road
How to solve multi-channel customer communication problems in independent stations? This cross-border e-commerce plug-in must be known!
Shadertoy基础教学02、画笑脸
servlet自学笔记
MVVM has become history, and Google has fully turned to MVI
微信小程序:爱情保证书制作生成
AlertManager告警的单独使用及prometheus配置告警规则使用
dolphinscheduler海豚调度升级代码改造-UpgradeDolphinScheduler
Learn to draw Er graph in an article
ICer技能02makefile脚本自跑vcs仿真
Abnova acid phosphatase (wheat germ) instructions
ICer技能02makefile脚本自跑vcs仿真
dolphinscheduler 2.0.5 spark 任务测试总结(源码优化)