当前位置:网站首页>随笔记:插入排序 --from wcc
随笔记:插入排序 --from wcc
2022-06-28 23:43:00 【Run Coder】
插入排序
插入排序( insertion sorting)是一种从序列左端开始依次对数据进行排序的算法。在排序过程中,左侧的数据陆续归位,而右侧留下的就是还未被排序的数据。插入排序的思路就是从右侧的未排序区域内取出一个数据,然后将它插入到已排序区域内合适的位置上。
思路:
1.默认从 i = 1 开始判断,这样 preIndex 自然是内部循环的游标;
2.current 保存 arr[i],通过循环来确定 current 的最终位置;
3.每个内循环开始的时候,arr[i] === current === arr[preIndex + 1],所以在内循环首次时 arr[preIndex + 1] = arr[preIndex] 的时候不必担心 arr[i] 的值丢失;
4.总体思路是,需要排位的元素先额外缓存起来,然后套用内循环,使得需要调整的元素赋值给它后面的一个位置上,形成依次挪位,
最后因为内循环在判断条件不生效的时候停止意味着找到了需要排位的元素的正确位置,然后赋值上去,完成排序
人类最伟大的地方就在于总能想出办法解决问题 --wcc
边栏推荐
- Stm32f407 ------- GPIO input experiment
- 机器学习6-决策树
- How many locks are added to an update statement? Take you to understand the underlying principles
- 网上注册股票开户很困难么?在线开户是安全么?
- stm32F407-------RTC实时时钟
- [stm32 Hal library] serial port communication
- At the end of June, how many people in Kangkang are ready to change jobs
- stm32F407-------NVIC中断优先级管理
- 机器学习4-降维技术
- mysql-5.7.30-winx64免安装版下载安装教程
猜你喜欢

stm32F407-------RTC实时时钟

ERROR 1067 (42000): Invalid default value for ‘end_ time‘ Mysql

Counting sorting and stability of sorting

Association line exploration, how to connect the two nodes of the flow chart
![[conception de la machine d'état] Moore, Mealy State Machine, Three - stage, Two - stage, one - stage State Machine Writing Specification](/img/48/e29f34aff7cc437bfb574591d54e3d.png)
[conception de la machine d'état] Moore, Mealy State Machine, Three - stage, Two - stage, one - stage State Machine Writing Specification

The picture display on the left of the two column layout is determined by the content height on the right

Blue Bridge Cup top ten common heaven level skill - breath of water The type of one recursion
![[stm32 Hal library] serial port communication](/img/2c/23a2ecf75141b8f38ab99ac6b2eaef.png)
[stm32 Hal library] serial port communication

Stm32f407-------- NVIC interrupt priority management

Learning fuzzy from SQL injection to bypass the latest safe dog WAF
随机推荐
Class extension and optional type extension of dart
stm32F407-------IO引脚复用映射
Is it safe to open a stock account on the Internet?
再次上榜!知道创宇入选2022中国网安产业竞争力50强
[word Tutorial Series Part 1] how to remove arrows in word tables
网上注册股票开户很困难么?在线开户是安全么?
Machine learning 4-dimension reduction technology
stm32F407-------寄存器地址名称映射分析
[stm32 Hal library] serial port communication
Auto encoder
MATLAB 学习笔记(6)MATLAB 的 upsample 函数和 downsample 函数
stm32F407-------GPIO输入实验
ctfshow XSS
stm32F407-------时钟系统(SystemInit时钟初始化、Systick滴答定时器)
Chapter II Classic synchronous exercises
[Electronic Experiment 2] simple electronic doorbell
Is it reliable and safe to avoid five in case of stock trading account opening
[SSM] an error is reported that the user name of the access denied for user 'WYF' @ 'localhost' (using password: yes) data becomes the user name of the computer
ctfshow XSS
机器学习4-降维技术