当前位置:网站首页>随笔记:插入排序 --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
边栏推荐
- Yes, use local_ setup. Bash or setup bash
- Three communication skills in software testing
- Design e-commerce seckill system
- MySQL connection query is easy to understand
- The second session of question swiping and clock out activity -- solving the switching problem with recursion as the background (2)
- Class extension and optional type extension of dart
- Thinking about lever
- Add the premise of ganggan
- SQL note 2 [MySQL]
- Scrapy使用xlwt实现将数据以Excel格式导出的Exporter
猜你喜欢

MATLAB 学习笔记(6)MATLAB 的 upsample 函数和 downsample 函数

At the end of June, how many people in Kangkang are ready to change jobs

Windows10 phpstudy installing redis extension

Chapter III processor scheduling exercise
![[stm32 Hal library] RTC and BKP drives](/img/72/c2c46377d0a2a5a032802640ca0201.png)
[stm32 Hal library] RTC and BKP drives
![[opencv] - linear filtering: box filtering, mean filtering, Gaussian filtering](/img/1d/3a46517cbfa90005a15d7858d81ca9.png)
[opencv] - linear filtering: box filtering, mean filtering, Gaussian filtering

CMake教程(一)

The secondary market is full of bad news. How should the market go next? One article will show you the general trend

Stm32f407 ------- GPIO input experiment

stm32F407-------通用定时器
随机推荐
Machine learning 6-decision tree
mysql-5.7.30-winx64免安装版下载安装教程
Association line exploration, how to connect the two nodes of the flow chart
PHP uses curl to download Excel files after logging in to the website
MATLAB 学习笔记(6)MATLAB 的 upsample 函数和 downsample 函数
[stm32 HAL库] 串口通信
解决ConfigParser解析中文问题
是使用local_setup.bash 还是 setup.bash
window10 phpstudy 安装redis扩展
PHP uses endroid/qrcode QR code to generate, and Gd library generates sharing posters
The second session of question swiping and clock out activity -- solving the switching problem with recursion as the background (2)
Stm32f407------- general timer
一条update语句到底加了多少锁?带你深入理解底层原理
Matlab learning notes (6) upsample function and downsample function of MATLAB
Counting sorting and stability of sorting
【LeetCode】21. 合并两个有序链表 - Go 语言题解
stm32F407-------NVIC中断优先级管理
pymysql.Error 获取错误码与具体错误信息
[machine learning] numerical analysis 02 -- finding roots of arbitrary equations
Rongyun communication solution solves the pain points of enterprise communication