当前位置:网站首页>With notes: insert sort --from WCC
With notes: insert sort --from WCC
2022-06-28 23:47:00 【Run Coder】
Insertion sort
Insertion sort ( insertion sorting) It is an algorithm that sorts data from the left end of the sequence . During sorting , The data on the left is coming back , What's left on the right is the data that hasn't been sorted yet . The idea of insertion sort is to take out a data from the unsorted area on the right , Then insert it in the right place in the sorted area .
Ideas :
1. The default from the i = 1 Start judging , such preIndex Nature is the cursor of the internal loop ;
2.current preservation arr[i], Determine by cycling current The final position of ;
3. At the beginning of each internal cycle ,arr[i] === current === arr[preIndex + 1], So for the first time in the inner cycle arr[preIndex + 1] = arr[preIndex] You don't have to worry about arr[i] The value of is missing ;
4. The general idea is , The elements that need to be ranked are cached first , Then apply the internal circulation , So that the element to be adjusted is assigned to a position behind it , Form and move in turn ,
Finally, because the inner loop stops when the judgment condition does not take effect, it means that the correct position of the element to be ranked is found , Then assign the value , To complete the order
The greatest thing about human beings is that they can always think of ways to solve problems --wcc
边栏推荐
- IO playback function of FIO
- How to make two objects or arrays equal
- The second session of question swiping and clock out activity -- solving the switching problem with recursion as the background (2)
- Save data in Excel: use openpyxl to create multiple tables and set excel row limit
- When dialogfragment's onstop is completely invisible, call disass to exit the interface and report an error. Solution
- Mysql-5.7.30-winx64 installation free download and installation tutorial
- ERROR 1067 (42000): Invalid default value for ‘end_time‘ Mysql
- Add the premise of ganggan
- Is the compass stock software reliable? Is it safe to trade stocks on it?
- frameworks/base/core/res/res/values/symbols. Xml:3915: error: no definition for declared symbol solution
猜你喜欢

Yyds dry goods count 【 vs code work record III 】 set vs code format

Mobile heterogeneous computing technology - GPU OpenCL programming (basic)

IDC: Alibaba cloud ranks first in the market share of China's data governance platform in 2021

"Five considerations" for safe use of the Internet

【狀態機設計】Moore、Mealy狀態機、三段式、二段式、一段式狀態機書寫規範
![[stm32 Hal library] RTC and BKP drives](/img/72/c2c46377d0a2a5a032802640ca0201.png)
[stm32 Hal library] RTC and BKP drives

LinkedIn DataHub --- 经验分享

Online yaml to JSON tool

stm32F407-------跑马灯、蜂鸣器

Implementation of dynamic timer for quartz
随机推荐
入行数字IC验证后会做些什么?
Rongyun communication solution solves the pain points of enterprise communication
Online yaml to JSON tool
ERROR 1067 (42000): Invalid default value for ‘end_time‘ Mysql
Stm32f407----- register address name mapping analysis
stm32F407-------电容触摸按键
pymysql.Error 获取错误码与具体错误信息
Add the premise of ganggan
再次上榜!知道创宇入选2022中国网安产业竞争力50强
TypeScript -- 第一节:基础类型
PHP uses curl to download Excel files after logging in to the website
Would like to ask, how to open a stock account? Is it safe to open an account online?
Stm32f407------- external interrupt
随笔记:模拟类数组(array-like)的方法
【软件分析】软件分析、设计与建模迭代式详解
The second session of question swiping and clock out activity -- solving the switching problem with recursion as the background (2)
Scrapy uses xlwt to implement the exporter that exports data in Excel format
SQL note 2 [MySQL]
[C Primer Plus Chapter II after class programming questions]
I can't sleep