当前位置:网站首页>随笔记:插入排序 --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
边栏推荐
- Oil monkey script learning
- fio的IO重放功能
- Is it safe to open a stock account on the Internet?
- Form verification problem - El select (solution to automatically trigger verification on initialization page)
- Machine learning 6-decision tree
- Is it safe and reliable to open a securities account in Yixue school?
- 入行数字IC验证后会做些什么?
- Design e-commerce seckill system
- mysql-5.7.30-winx64免安装版下载安装教程
- Association line exploration, how to connect the two nodes of the flow chart
猜你喜欢

Stm32f407 ------ running lamp and buzzer

Stm32f407 ------- IO pin multiplexing mapping

Don't ask me how to do UI automation test again

mysql-5.7.30-winx64免安装版下载安装教程

机器学习4-降维技术

Implementation of dynamic timer for quartz

lock4j--分布式锁中间件--使用/实例

Quartz explanation and use

Stm32f407------- general timer

Stm32f407 ------ clock system (systeminit clock initialization, systick tick timer)
随机推荐
stm32F407-------电容触摸按键
Picture 64base transcoding and decoding
stm32F407-------IO引脚复用映射
【C Primer Plus第二章課後編程題】
[word Tutorial Series Part 1] how to remove arrows in word tables
再次上榜!知道创宇入选2022中国网安产业竞争力50强
百度知道爬虫,根据问题id,线索id,评论id获取评论下面的对话
mysql-5.7.30-winx64免安装版下载安装教程
《英语语法新思维 基础版2》读书笔记(一)
Stm32f407 ------ running lamp and buzzer
关联线探究,如何连接流程图的两个节点
Three communication skills in software testing
Advice to friends
TDD case practice
MSCI 2022 market classification assessment
[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
stm32F407-------时钟系统(SystemInit时钟初始化、Systick滴答定时器)
urllib.parse 解析url连接中的参数
[mathematical modeling] fmincon() function of MATLAB nonlinear programming
Stm32f407----- capacitive touch button