当前位置:网站首页>经典排序之插入排序
经典排序之插入排序
2022-07-30 05:45:00 【尹平华】
//递增
void asc_insert_sort(int arr[], int len)
{
int i, j;
for (i=1;i<len;i++){
if (arr[i]<arr[i-1]){
int temp = arr[i];
for (j=i;arr[j-1]>temp&&j>0;j--){
arr[j] = arr[j - 1];
}
arr[j] = temp;
}
}
}
//递减
void desc_insert_sort(int arr[], int len)
{
int i, j;
for (i = 1;i < len;i++) {
if (arr[i] > arr[i - 1]) {
int temp = arr[i];
for (j = i;arr[j - 1] < temp && j > 0;j--) {
arr[j] = arr[j - 1];
}
arr[j] = temp;
}
}
}
边栏推荐
- “R语言+遥感”的水环境综合评价方法
- 边境的悍匪—机器学习实战:第十章 Keras人工神经网络简介
- The first WebAssembly program
- Self-augmented Unpaired Image Dehazing via Density and Depth Decomposition program running record
- MATLAB怎么在图像中显示nii文件切片信息?
- HSPF 模型应用
- protobuf coding and network communication applications (1)
- QT连载3:基于QT和STM32H750的LORA试验平台(2)
- protobuf编码及网络通信应用(一)
- 卷积神经网络(CNN)之卷积操作、池化操作、激活函数
猜你喜欢

protobuf coding and network communication applications (1)

常用损失函数(二):Dice Loss

R语言 生态环境领域应用

目标检测中的知识蒸馏方法

十六、Kotlin进阶学习:协程详细学习。

Trust anchor for certification path not found.异常解决方法。

昆仑通态屏幕制作(连载1)---接触篇

什么是过拟合、欠拟合现象以及如何缓解?

Application of remote sensing, GIS and GPS technology in hydrology, meteorology, disaster, ecology, environment and health

工厂模式(Swift 实现)
随机推荐
边境的悍匪—机器学习实战:第五章 支持向量机
基于R语言地理加权回归、主成分分析、判别分析等空间异质性数据分析
QT串口动态实时显示大量数据波形曲线(四)========“界面的美化与处理”
第一个WebAssembly程序
基于遥感解译与GIS技术环境影响评价图件制作(最新导则)
【总结】工业检测项目中如何选择合适的损失函数
Jdbc & Mysql timeout分析
DeepLearing4j's deep learning Yolo Tiny realizes target detection
十八、Kotlin进阶学习:1、挂起函数执行的顺序;2、使用 async 和 await 异步执行挂起函数;3、协程的调度器;4、父子协程;
Redis 发布/订阅
Rsync realizes folder or data synchronization between Win systems
“R语言+遥感”的水环境综合评价方法
Basic application of XMLBean
QT串口动态实时显示大量数据波形曲线(五)========“最终完美解决版”
Meta分析在生态环境领域里的应用
Flink-stream/batch/OLAP integrated to get Flink engine
十一、Kotlin进阶学习:1、集合;2、List操作;3、可变集合——MutableList;4、Set;5、Map;6、MutableMap;
昆仑通态屏幕制作(连载3)---基础篇(按钮串口发送)
21. Kotlin Advanced Learning: Implementing Simple Network Access Encapsulation
正则表达式语法详解及实用实例