当前位置:网站首页>排序---插入排序
排序---插入排序
2022-08-07 06:55:00 【草莓味巧克力豆】
是简单排序中效率最好的
思路
插入排序的思想的核心就是局部有序
局部有序的含义:
在一个队列中的人,我们选择其中一个作为标记的队员。
在这个标记的队员左边的所有队员已经是局部有序的
这意味的,有一部分人是按顺序排好的,有部分人还没有排序。

function insertSort(nums){
// 外层循环,从第0个位置开始获取数据,向前面局部有序进行插入
for(let i = 0;i < nums.length;i++){
// 内层循环,获取i的位置的元素,和前面的数据依次进行比较
let temp = nums[i]
let j = i
// 比该值大的元素往后移
while(nums[j - 1] > temp && j > 0){
nums[j] = nums[j - 1]
j--
}
// 将j位置上的数据,放置temp就可以
nums[j] = temp
}
}
时间复杂度:o(n^2)
边栏推荐
- netstat & firewall
- 为什么NIO比BIO效率高
- Dark horse Cookie&Session programmers session
- In-depth analysis of HyperBDR cloud disaster recovery 2: Self-developed Boot in Cloud technology to achieve highly automated cloud disaster recovery
- 什么值得买面试题(一)
- VoLTE Basic Self-Learning Series | What are transparent data and non-transparent data in VoLTE?
- 别看了,这就是你的题呀(二)
- grid网格布局
- VoLTE Basic Self-study Series | Summary
- 【C语言】内存函数
猜你喜欢

Learning salient boundary feature for anchor-free temporal action localization AFSD阅读笔记

LeetCode sword refers to Offer 09. Two stack is used to implement a queue

图论与网络模型——基于R

VoLTE Basic Self-Learning Series | VoLTE Network Architecture
【C语言】内存函数

VoLTE基础自学系列 | IMS网络概述

Top 20 most popular plugins for QGIS

LeetCode 剑指 Offer 09. 用两个栈实现队列

VoLTE Basic Self-Learning Series | Which scenarios will trigger CSFB on VoLTE terminals?

servlet tutorial 2: return to the jsp page
随机推荐
spyder/conda安装包报错:conda info could not be constructed. KeyError: ‘pkgs_dirs‘
如何搭建神经网络模型,多层全连接神经网络
How to use the @Async annotation
leetcode 110. Balanced Binary Trees
Redis 定长队列的探索和实践
VoLTE基础自学系列 | 汇总
CTO强烈禁止使用Calendar,那用啥?
GBL210-ASEMI机箱电源适配器整流桥GBL210
VoLTE Basic Self-Learning Series | Enterprise Voice Network Brief
有 5nm 制程工艺的 MCU 吗?
LeetCode刷题笔记:899.有序队列
ansible当中模块的使用
leetcode 110. 平衡二叉树
devserver configuration
Qt uses SQLite's performance-optimized billion-point record
VoLTE Basic Self-Learning Series | What is Silent Redial in VoLTE?How does it relate to CSFB?
Comparison and summary of the four methods of DOM, SAX, JDOM, and DOM4J
NIO learning
LeetCode points to Offer 24. Reverse linked list
LeetCode 1408. 数组中的字符串匹配